mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
remove simple white space and order changes to make review less noisy
This commit is contained in:
parent
0525b144b7
commit
5d4611f83f
@ -13,6 +13,7 @@ export const userFactory = async (
|
||||
user: UserInterface,
|
||||
): Promise<User> => {
|
||||
const { mutate } = client
|
||||
|
||||
const homeCom = await writeHomeCommunityEntry()
|
||||
// console.log('call createUser with', JSON.stringify(user, null, 2))
|
||||
const response = await mutate({ mutation: createUser, variables: user })
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`
|
||||
CREATE TABLE \`dlt_users\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`user_id\` int(10) unsigned NOT NULL,
|
||||
\`message_id\` varchar(64) NULL DEFAULT NULL,
|
||||
\`verified\` tinyint(4) NOT NULL DEFAULT 0,
|
||||
\`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
\`verified_at\` datetime(3),
|
||||
\`error\` text NULL DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`)
|
||||
|
||||
await queryFn(
|
||||
'ALTER TABLE `dlt_transactions` RENAME COLUMN `transactions_id` TO `transaction_id`;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `dlt_transactions` ADD COLUMN `error` text NULL DEFAULT NULL;')
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`DROP TABLE \`dlt_users\`;`)
|
||||
|
||||
await queryFn(
|
||||
'ALTER TABLE `dlt_transactions` RENAME COLUMN `transaction_id` TO `transactions_id`;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `dlt_transactions` DROP COLUMN `error`;')
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`DROP TABLE \`dlt_users\`;`)
|
||||
await queryFn(`
|
||||
ALTER TABLE \`dlt_transactions\`
|
||||
CHANGE \`transaction_id\` \`transaction_id\` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||
ADD \`user_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`transaction_id\`,
|
||||
ADD \`transaction_link_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`user_id\`,
|
||||
ADD \`type_id\` INT UNSIGNED NOT NULL AFTER \`transaction_link_id\`
|
||||
;
|
||||
`)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`
|
||||
CREATE TABLE \`dlt_users\` (
|
||||
\`id\` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`user_id\` int(10) unsigned NOT NULL,
|
||||
\`message_id\` varchar(64) NULL DEFAULT NULL,
|
||||
\`verified\` tinyint(4) NOT NULL DEFAULT 0,
|
||||
\`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
\`verified_at\` datetime(3),
|
||||
\`error\` text NULL DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`)
|
||||
|
||||
await queryFn(`
|
||||
ALTER TABLE \`dlt_transactions\`
|
||||
CHANGE \`transaction_id\` \`transaction_id\` INT(10) UNSIGNED NOT NULL,
|
||||
DROP COLUMN \`user_id\`,
|
||||
DROP COLUMN \`transaction_link_id\`
|
||||
DROP COLUMN \`type_id\`
|
||||
;
|
||||
`)
|
||||
}
|
||||
26
database/migration/migrations/0096-upgrade_dlt_tables.ts
Normal file
26
database/migration/migrations/0096-upgrade_dlt_tables.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`
|
||||
ALTER TABLE \`dlt_transactions\`
|
||||
CHANGE \`transactions_id\` \`transaction_id\` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||
ADD \`user_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`transaction_id\`,
|
||||
ADD \`transaction_link_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`user_id\`,
|
||||
ADD \`type_id\` INT UNSIGNED NOT NULL AFTER \`transaction_link_id\`,
|
||||
ADD \`error\` text NULL DEFAULT NULL AFTER \`verified_at\`,
|
||||
;
|
||||
`)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`
|
||||
ALTER TABLE \`dlt_transactions\`
|
||||
CHANGE \`transaction_id\` \`transactions_id\` INT(10) UNSIGNED NOT NULL,
|
||||
DROP COLUMN \`user_id\`,
|
||||
DROP COLUMN \`transaction_link_id\`,
|
||||
DROP COLUMN \`type_id\`,
|
||||
DROP COLUMN \`error\`
|
||||
;
|
||||
`)
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
import { getLogger } from 'log4js'
|
||||
import { DataSource as DBDataSource, FileLogger } from 'typeorm'
|
||||
import { Migration, entities } from './entity'
|
||||
import { getLogger } from 'log4js'
|
||||
import { latestDbVersion } from '.'
|
||||
import { CONFIG } from './config'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from './config/const'
|
||||
import { entities, Migration } from './entity'
|
||||
|
||||
const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.AppDatabase`)
|
||||
|
||||
@ -92,7 +92,7 @@ export class AppDatabase {
|
||||
public async destroy(): Promise<void> {
|
||||
await this.dataSource?.destroy()
|
||||
}
|
||||
|
||||
|
||||
// ######################################
|
||||
// private methods
|
||||
// ######################################
|
||||
|
||||
@ -10,8 +10,8 @@ import {
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm'
|
||||
import { FederatedCommunity } from './FederatedCommunity'
|
||||
import { GeometryTransformer } from './transformer/GeometryTransformer'
|
||||
import { User } from './User'
|
||||
import { GeometryTransformer } from './transformer/GeometryTransformer'
|
||||
|
||||
@Entity('communities')
|
||||
export class Community extends BaseEntity {
|
||||
|
||||
@ -12,8 +12,8 @@ import {
|
||||
} from 'typeorm'
|
||||
import { ContributionMessage } from './ContributionMessage'
|
||||
import { Transaction } from './Transaction'
|
||||
import { DecimalTransformer } from './transformer/DecimalTransformer'
|
||||
import { User } from './User'
|
||||
import { DecimalTransformer } from './transformer/DecimalTransformer'
|
||||
|
||||
@Entity('contributions')
|
||||
export class Contribution extends BaseEntity {
|
||||
|
||||
@ -13,8 +13,8 @@ import { ContributionLink } from './ContributionLink'
|
||||
import { ContributionMessage } from './ContributionMessage'
|
||||
import { Transaction } from './Transaction'
|
||||
import { TransactionLink } from './TransactionLink'
|
||||
import { DecimalTransformer } from './transformer/DecimalTransformer'
|
||||
import { User } from './User'
|
||||
import { DecimalTransformer } from './transformer/DecimalTransformer'
|
||||
|
||||
@Entity('events')
|
||||
export class Event extends BaseEntity {
|
||||
|
||||
@ -15,9 +15,9 @@ import { Contribution } from './Contribution'
|
||||
import { ContributionMessage } from './ContributionMessage'
|
||||
import { DltTransaction } from './DltTransaction'
|
||||
import { TransactionLink } from './TransactionLink'
|
||||
import { GeometryTransformer } from './transformer/GeometryTransformer'
|
||||
import { UserContact } from './UserContact'
|
||||
import { UserRole } from './UserRole'
|
||||
import { GeometryTransformer } from './transformer/GeometryTransformer'
|
||||
|
||||
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import util from 'util'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
|
||||
export abstract class AbstractLoggingView {
|
||||
protected bufferStringFormat: BufferEncoding = 'hex'
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { PendingTransactionState } from 'shared'
|
||||
import { PendingTransaction, Transaction } from '../entity'
|
||||
import { AbstractLoggingView } from './AbstractLogging.view'
|
||||
import { TransactionLoggingView } from './TransactionLogging.view'
|
||||
import { PendingTransactionState } from 'shared'
|
||||
|
||||
export class PendingTransactionLoggingView extends AbstractLoggingView {
|
||||
public constructor(private self: PendingTransaction) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { Community as DbCommunity, FederatedCommunity as DbFederatedCommunity } from '..'
|
||||
import { AppDatabase } from '../AppDatabase'
|
||||
import { getCommunityByPublicKeyOrFail, getHomeCommunity, getHomeCommunityWithFederatedCommunityOrFail, getReachableCommunities } from './communities'
|
||||
import { describe, expect, it, beforeEach, beforeAll, afterAll } from 'vitest'
|
||||
import { createCommunity, createVerifiedFederatedCommunity } from '../seeds/community'
|
||||
import { Ed25519PublicKey } from 'shared'
|
||||
|
||||
@ -117,4 +117,4 @@ describe('community.queries', () => {
|
||||
expect(await getReachableCommunities(1000)).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -27,9 +27,7 @@ export async function getCommunityByUuid(communityUuid: string): Promise<DbCommu
|
||||
})
|
||||
}
|
||||
|
||||
export function findWithCommunityIdentifier(
|
||||
communityIdentifier: string,
|
||||
): FindOptionsWhere<DbCommunity> {
|
||||
export function findWithCommunityIdentifier(communityIdentifier: string): FindOptionsWhere<DbCommunity> {
|
||||
const where: FindOptionsWhere<DbCommunity> = {}
|
||||
// pre filter identifier type to reduce db query complexity
|
||||
if (urlSchema.safeParse(communityIdentifier).success) {
|
||||
@ -71,15 +69,15 @@ export async function getCommunityByPublicKeyOrFail(publicKey: Ed25519PublicKey)
|
||||
// home community and all federated communities which have been verified within the last authenticationTimeoutMs
|
||||
export async function getReachableCommunities(
|
||||
authenticationTimeoutMs: number,
|
||||
order?: FindOptionsOrder<DbCommunity>,
|
||||
order?: FindOptionsOrder<DbCommunity>
|
||||
): Promise<DbCommunity[]> {
|
||||
return await DbCommunity.find({
|
||||
where: [
|
||||
{
|
||||
authenticatedAt: Not(IsNull()),
|
||||
federatedCommunities: {
|
||||
where: [
|
||||
{
|
||||
authenticatedAt: Not(IsNull()),
|
||||
federatedCommunities: {
|
||||
verifiedAt: MoreThanOrEqual(new Date(Date.now() - authenticationTimeoutMs)),
|
||||
},
|
||||
}
|
||||
},
|
||||
{ foreign: false },
|
||||
],
|
||||
@ -94,4 +92,4 @@ export async function getNotReachableCommunities(
|
||||
where: { authenticatedAt: IsNull(), foreign: true },
|
||||
order,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'
|
||||
|
||||
export * from './user'
|
||||
export * from './communities'
|
||||
export * from './events'
|
||||
export * from './pendingTransactions'
|
||||
export * from './transactionLinks'
|
||||
export * from './transactions'
|
||||
export * from './user'
|
||||
export * from './transactionLinks'
|
||||
export * from './communityHandshakes'
|
||||
|
||||
export const LOG4JS_QUERIES_CATEGORY_NAME = `${LOG4JS_BASE_CATEGORY_NAME}.queries`
|
||||
|
||||
@ -1,22 +1,22 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { PendingTransactionState } from 'shared'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
||||
import {
|
||||
Community as DbCommunity,
|
||||
PendingTransaction as DbPendingTransaction,
|
||||
User as DbUser,
|
||||
UserContact as DbUserContact,
|
||||
Community as DbCommunity,
|
||||
} from '..'
|
||||
import { countOpenPendingTransactions } from './pendingTransactions'
|
||||
import { PendingTransactionState } from 'shared'
|
||||
import { AppDatabase } from '../AppDatabase'
|
||||
import { createCommunity } from '../seeds/community'
|
||||
import { pendingTransactionFactory } from '../seeds/factory/pendingTransaction'
|
||||
import { userFactory } from '../seeds/factory/user'
|
||||
import { pendingTransactionFactory } from '../seeds/factory/pendingTransaction'
|
||||
import { bibiBloxberg } from '../seeds/users/bibi-bloxberg'
|
||||
import { peterLustig } from '../seeds/users/peter-lustig'
|
||||
import { bobBaumeister } from '../seeds/users/bob-baumeister'
|
||||
import { garrickOllivander } from '../seeds/users/garrick-ollivander'
|
||||
import { peterLustig } from '../seeds/users/peter-lustig'
|
||||
import { countOpenPendingTransactions } from './pendingTransactions'
|
||||
import { describe, expect, it, beforeAll, afterAll } from 'vitest'
|
||||
import { createCommunity } from '../seeds/community'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import Decimal from 'decimal.js-light'
|
||||
|
||||
const db = AppDatabase.getInstance()
|
||||
|
||||
@ -27,6 +27,7 @@ afterAll(async () => {
|
||||
await db.destroy()
|
||||
})
|
||||
|
||||
|
||||
describe('countOpenPendingTransactions', () => {
|
||||
let bibi: DbUser
|
||||
let peter: DbUser
|
||||
@ -40,44 +41,45 @@ describe('countOpenPendingTransactions', () => {
|
||||
|
||||
await createCommunity(false)
|
||||
|
||||
bibi = await userFactory(bibiBloxberg)
|
||||
bibi = await userFactory(bibiBloxberg)
|
||||
peter = await userFactory(peterLustig)
|
||||
bob = await userFactory(bobBaumeister)
|
||||
garrick = await userFactory(garrickOllivander)
|
||||
|
||||
// Bibi -> Peter
|
||||
await pendingTransactionFactory(
|
||||
bibi,
|
||||
peter,
|
||||
new Decimal(10),
|
||||
'Bibi -> Peter new',
|
||||
PendingTransactionState.NEW,
|
||||
bibi,
|
||||
peter,
|
||||
new Decimal(10),
|
||||
'Bibi -> Peter new',
|
||||
PendingTransactionState.NEW
|
||||
)
|
||||
await pendingTransactionFactory(
|
||||
bibi,
|
||||
peter,
|
||||
new Decimal(100.01),
|
||||
'Bibi -> Peter settled',
|
||||
PendingTransactionState.SETTLED,
|
||||
bibi,
|
||||
peter,
|
||||
new Decimal(100.01),
|
||||
'Bibi -> Peter settled',
|
||||
PendingTransactionState.SETTLED
|
||||
)
|
||||
|
||||
// Peter -> Bibi
|
||||
await pendingTransactionFactory(
|
||||
peter,
|
||||
bibi,
|
||||
new Decimal(12),
|
||||
'Peter -> Bibi new',
|
||||
PendingTransactionState.NEW,
|
||||
peter,
|
||||
bibi,
|
||||
new Decimal(12),
|
||||
'Peter -> Bibi new',
|
||||
PendingTransactionState.NEW
|
||||
)
|
||||
|
||||
// Bob -> Peter
|
||||
await pendingTransactionFactory(
|
||||
bob,
|
||||
peter,
|
||||
new Decimal(17.1),
|
||||
'Bob -> Peter new',
|
||||
PendingTransactionState.NEW,
|
||||
bob,
|
||||
peter,
|
||||
new Decimal(17.1),
|
||||
'Bob -> Peter new',
|
||||
PendingTransactionState.NEW
|
||||
)
|
||||
|
||||
})
|
||||
it('should return 0 if called with empty array', async () => {
|
||||
const count = await countOpenPendingTransactions([])
|
||||
@ -102,20 +104,21 @@ describe('countOpenPendingTransactions', () => {
|
||||
it('peter and bob have one transaction together, peter two additional, should return 3', async () => {
|
||||
const count = await countOpenPendingTransactions([peter.gradidoID, bob.gradidoID])
|
||||
expect(count).toBe(3)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
it('peter has three transactions, should return 3', async () => {
|
||||
const count = await countOpenPendingTransactions([peter.gradidoID])
|
||||
expect(count).toBe(3)
|
||||
})
|
||||
|
||||
|
||||
it('bibi has two transactions, should return 2', async () => {
|
||||
const count = await countOpenPendingTransactions([bibi.gradidoID])
|
||||
expect(count).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
it('bob has one transaction, should return 1', async () => {
|
||||
const count = await countOpenPendingTransactions([bob.gradidoID])
|
||||
expect(count).toBe(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { PendingTransactionState } from 'shared'
|
||||
import { In } from 'typeorm'
|
||||
import { PendingTransaction as DbPendingTransaction } from '../entity'
|
||||
import { In } from 'typeorm'
|
||||
import { PendingTransactionState } from 'shared'
|
||||
|
||||
/**
|
||||
* Counts the number of open pending transactions for the given users.
|
||||
@ -15,4 +15,4 @@ export async function countOpenPendingTransactions(users: string[]): Promise<num
|
||||
],
|
||||
})
|
||||
return count
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import { TransactionLink as DbTransactionLink } from '../entity'
|
||||
import { TransactionLink as DbTransactionLink } from "../entity"
|
||||
|
||||
export async function findTransactionLinkByCode(code: string): Promise<DbTransactionLink> {
|
||||
return await DbTransactionLink.findOneOrFail({
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { clearLogs, getLogger, printLogs } from '../../../config-schema/test/testSetup.vitest'
|
||||
import { Community as DbCommunity, User as DbUser, UserContact as DbUserContact } from '..'
|
||||
import { User as DbUser, UserContact as DbUserContact, Community as DbCommunity } from '../entity'
|
||||
import { AppDatabase } from '../AppDatabase'
|
||||
import { createCommunity } from '../seeds/community'
|
||||
import { aliasExists, findUserByIdentifier } from './user'
|
||||
import { userFactory } from '../seeds/factory/user'
|
||||
import { bibiBloxberg } from '../seeds/users/bibi-bloxberg'
|
||||
import { bobBaumeister } from '../seeds/users/bob-baumeister'
|
||||
import { describe, expect, it, beforeAll, afterAll, beforeEach, } from 'vitest'
|
||||
import { createCommunity } from '../seeds/community'
|
||||
import { peterLustig } from '../seeds/users/peter-lustig'
|
||||
import { bobBaumeister } from '../seeds/users/bob-baumeister'
|
||||
import { getLogger, printLogs, clearLogs } from '../../../config-schema/test/testSetup.vitest'
|
||||
import { LOG4JS_QUERIES_CATEGORY_NAME } from '.'
|
||||
import { aliasExists, findUserByIdentifier } from './user'
|
||||
|
||||
const db = AppDatabase.getInstance()
|
||||
const userIdentifierLoggerName = `${LOG4JS_QUERIES_CATEGORY_NAME}.user.findUserByIdentifier`
|
||||
@ -26,9 +26,9 @@ describe('user.queries', () => {
|
||||
await DbUser.clear()
|
||||
await DbUserContact.clear()
|
||||
|
||||
const bibi = bibiBloxberg
|
||||
const bibi = bibiBloxberg
|
||||
bibi.alias = 'b-b'
|
||||
await userFactory(bibi)
|
||||
await userFactory(bibi)
|
||||
})
|
||||
|
||||
it('should return true if alias exists', async () => {
|
||||
@ -70,12 +70,12 @@ describe('user.queries', () => {
|
||||
const user = await findUserByIdentifier(userBibi.gradidoID, communityUuid)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
})
|
||||
|
||||
|
||||
it('userIdentifier is alias', async () => {
|
||||
const user = await findUserByIdentifier(userBibi.alias, communityUuid)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
})
|
||||
|
||||
|
||||
it('userIdentifier is email', async () => {
|
||||
const user = await findUserByIdentifier(userBibi.emailContact.email, communityUuid)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
@ -85,18 +85,18 @@ describe('user.queries', () => {
|
||||
expect(user).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe('communityIdentifier is community name', () => {
|
||||
it('userIdentifier is gradido id', async () => {
|
||||
const user = await findUserByIdentifier(userBibi.gradidoID, communityName)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
})
|
||||
|
||||
|
||||
it('userIdentifier is alias', async () => {
|
||||
const user = await findUserByIdentifier(userBibi.alias, communityName)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
})
|
||||
|
||||
|
||||
it('userIdentifier is email', async () => {
|
||||
const user = await findUserByIdentifier(userBibi.emailContact.email, communityName)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
@ -117,12 +117,12 @@ describe('user.queries', () => {
|
||||
const user = await findUserByIdentifier(userBibi.gradidoID)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
})
|
||||
|
||||
|
||||
it('userIdentifier is alias', async () => {
|
||||
const user = await findUserByIdentifier(userBibi.alias)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
})
|
||||
|
||||
|
||||
it('userIdentifier is email', async () => {
|
||||
const user = await findUserByIdentifier(userBibi.emailContact.email)
|
||||
expect(user).toMatchObject(userBibi)
|
||||
@ -130,12 +130,10 @@ describe('user.queries', () => {
|
||||
it('userIdentifier is unknown type', async () => {
|
||||
const user = await findUserByIdentifier('sa')
|
||||
printLogs()
|
||||
expect(getLogger(userIdentifierLoggerName).warn).toHaveBeenCalledWith(
|
||||
'Unknown identifier type',
|
||||
'sa',
|
||||
)
|
||||
expect(getLogger(userIdentifierLoggerName).warn).toHaveBeenCalledWith('Unknown identifier type', 'sa')
|
||||
expect(user).toBeNull()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { getLogger } from 'log4js'
|
||||
import { aliasSchema, emailSchema, uuidv4Schema } from 'shared'
|
||||
import { Raw } from 'typeorm'
|
||||
import { User as DbUser, UserContact as DbUserContact } from '../entity'
|
||||
import { aliasSchema, emailSchema, uuidv4Schema } from 'shared'
|
||||
import { getLogger } from 'log4js'
|
||||
import { findWithCommunityIdentifier, LOG4JS_QUERIES_CATEGORY_NAME } from './index'
|
||||
|
||||
export async function aliasExists(alias: string): Promise<boolean> {
|
||||
@ -32,8 +32,8 @@ export const findUserByIdentifier = async (
|
||||
identifier: string,
|
||||
communityIdentifier?: string,
|
||||
): Promise<DbUser | null> => {
|
||||
const communityWhere = communityIdentifier
|
||||
? findWithCommunityIdentifier(communityIdentifier)
|
||||
const communityWhere = communityIdentifier
|
||||
? findWithCommunityIdentifier(communityIdentifier)
|
||||
: undefined
|
||||
|
||||
if (uuidv4Schema.safeParse(identifier).success) {
|
||||
@ -52,12 +52,12 @@ export const findUserByIdentifier = async (
|
||||
},
|
||||
relations: { user: { community: true } },
|
||||
})
|
||||
if (userContact) {
|
||||
if (userContact) {
|
||||
// TODO: remove circular reference
|
||||
const user = userContact.user
|
||||
user.emailContact = userContact
|
||||
return user
|
||||
}
|
||||
}
|
||||
} else if (aliasSchema.safeParse(identifier).success) {
|
||||
return await DbUser.findOne({
|
||||
where: { alias: identifier, community: communityWhere },
|
||||
@ -65,10 +65,7 @@ export const findUserByIdentifier = async (
|
||||
})
|
||||
} else {
|
||||
// should don't happen often, so we create only in the rare case a logger for it
|
||||
getLogger(`${LOG4JS_QUERIES_CATEGORY_NAME}.user.findUserByIdentifier`).warn(
|
||||
'Unknown identifier type',
|
||||
identifier,
|
||||
)
|
||||
getLogger(`${LOG4JS_QUERIES_CATEGORY_NAME}.user.findUserByIdentifier`).warn('Unknown identifier type', identifier)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import { PendingTransactionState } from 'shared'
|
||||
import { PendingTransaction as DbPendingTransaction, User as DbUser } from '../..'
|
||||
import { PendingTransactionState } from 'shared'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
|
||||
export async function pendingTransactionFactory(
|
||||
sender: DbUser,
|
||||
@ -14,8 +14,8 @@ export async function pendingTransactionFactory(
|
||||
pendingTransaction.memo = memo
|
||||
pendingTransaction.amount = amount
|
||||
pendingTransaction.userId = sender.id
|
||||
pendingTransaction.userGradidoID = sender.gradidoID
|
||||
pendingTransaction.userCommunityUuid = sender.communityUuid!
|
||||
pendingTransaction.userGradidoID = sender.gradidoID
|
||||
pendingTransaction.userCommunityUuid = sender.communityUuid!
|
||||
pendingTransaction.linkedUserId = receiver.id
|
||||
pendingTransaction.linkedUserGradidoID = receiver.gradidoID
|
||||
pendingTransaction.linkedUserCommunityUuid = receiver.communityUuid!
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
import random from 'crypto-random-bigint'
|
||||
import { OptInType, PasswordEncryptionType, UserContactType } from 'shared'
|
||||
import { v4 } from 'uuid'
|
||||
import { User, UserContact } from '../../entity'
|
||||
import { getHomeCommunity } from '../../queries/communities'
|
||||
import { UserInterface } from '../users/UserInterface'
|
||||
import { User, UserContact } from '../../entity'
|
||||
import { v4 } from 'uuid'
|
||||
import { UserContactType, OptInType, PasswordEncryptionType } from 'shared'
|
||||
import { getHomeCommunity } from '../../queries/communities'
|
||||
import random from 'crypto-random-bigint'
|
||||
|
||||
export const userFactory = async (user: UserInterface): Promise<User> => {
|
||||
let dbUserContact = new UserContact()
|
||||
|
||||
dbUserContact.email = user.email ?? ''
|
||||
dbUserContact.type = UserContactType.USER_CONTACT_EMAIL
|
||||
|
||||
|
||||
let dbUser = new User()
|
||||
dbUser.firstName = user.firstName ?? ''
|
||||
dbUser.lastName = user.lastName ?? ''
|
||||
@ -35,11 +35,11 @@ export const userFactory = async (user: UserInterface): Promise<User> => {
|
||||
dbUser.community = homeCommunity
|
||||
dbUser.communityUuid = homeCommunity.communityUuid!
|
||||
}
|
||||
// TODO: improve with cascade
|
||||
// TODO: improve with cascade
|
||||
dbUser = await dbUser.save()
|
||||
dbUserContact.userId = dbUser.id
|
||||
dbUserContact = await dbUserContact.save()
|
||||
dbUser.emailId = dbUserContact.id
|
||||
dbUser.emailContact = dbUserContact
|
||||
return dbUser.save()
|
||||
}
|
||||
}
|
||||
@ -7,5 +7,5 @@ export const peterLustig: UserInterface = {
|
||||
// description: 'Latzhose und Nickelbrille',
|
||||
createdAt: new Date('2020-11-25T10:48:43'),
|
||||
emailChecked: true,
|
||||
language: 'de',
|
||||
language: 'de'
|
||||
}
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
export * from './TRANSACTION_LINK_LOCK'
|
||||
export * from './TRANSACTIONS_LOCK'
|
||||
export * from './TRANSACTION_LINK_LOCK'
|
||||
|
||||
@ -13,7 +13,7 @@ TYPEORM_LOGGING_RELATIVE_PATH=typeorm.dht-node.log
|
||||
# Federation
|
||||
# if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen on an hash created from this topic
|
||||
FEDERATION_DHT_TOPIC=GRADIDO_HUB
|
||||
FEDERATION_DHT_SEED=64ebcb0e3ad547848fed4197c6e1332f
|
||||
# FEDERATION_DHT_SEED=64ebcb0e3ad547848fef4197c6e2332f
|
||||
FEDERATION_COMMUNITY_URL=http://localhost
|
||||
# comma separated values, which apis should be announced
|
||||
FEDERATION_COMMUNITY_APIS=1_0
|
||||
Loading…
x
Reference in New Issue
Block a user