mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor: rebase master branch
This commit is contained in:
parent
1ed8c0a029
commit
c03b7a3b2c
2 changed files with 20 additions and 11 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable max-lines */
|
||||||
import type { BindMfa, CreateUser, MfaVerification, Scope, User } from '@logto/schemas';
|
import type { BindMfa, CreateUser, MfaVerification, Scope, User } from '@logto/schemas';
|
||||||
import { MfaFactor, RoleType, Users, UsersPasswordEncryptionMethod } from '@logto/schemas';
|
import { MfaFactor, RoleType, Users, UsersPasswordEncryptionMethod } from '@logto/schemas';
|
||||||
import { generateStandardShortId, generateStandardId } from '@logto/shared';
|
import { generateStandardShortId, generateStandardId } from '@logto/shared';
|
||||||
|
@ -123,14 +124,19 @@ export const createUserLibrary = (queries: Queries) => {
|
||||||
jsonbMode?: 'replace' | 'merge'
|
jsonbMode?: 'replace' | 'merge'
|
||||||
) => {
|
) => {
|
||||||
const validPhoneNumber = conditional(
|
const validPhoneNumber = conditional(
|
||||||
'primaryPhone' in set &&
|
typeof set.primaryPhone === 'string' && getValidPhoneNumber(set.primaryPhone)
|
||||||
typeof set.primaryPhone === 'string' &&
|
|
||||||
getValidPhoneNumber(set.primaryPhone)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return updateUserByIdQuery(
|
return updateUserByIdQuery(
|
||||||
id,
|
id,
|
||||||
{ ...set, ...conditional(validPhoneNumber && { primaryPhone: validPhoneNumber }) },
|
{
|
||||||
|
...set,
|
||||||
|
...conditional(
|
||||||
|
validPhoneNumber && {
|
||||||
|
primaryPhone: validPhoneNumber,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
},
|
||||||
jsonbMode
|
jsonbMode
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -148,9 +154,7 @@ export const createUserLibrary = (queries: Queries) => {
|
||||||
assertThat(parameterRoles.length === roleNames.length, 'role.default_role_missing');
|
assertThat(parameterRoles.length === roleNames.length, 'role.default_role_missing');
|
||||||
|
|
||||||
const validPhoneNumber = conditional(
|
const validPhoneNumber = conditional(
|
||||||
'primaryPhone' in data &&
|
typeof data.primaryPhone === 'string' && getValidPhoneNumber(data.primaryPhone)
|
||||||
typeof data.primaryPhone === 'string' &&
|
|
||||||
getValidPhoneNumber(data.primaryPhone)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return pool.transaction(async (connection) => {
|
return pool.transaction(async (connection) => {
|
||||||
|
@ -368,3 +372,4 @@ export const createUserLibrary = (queries: Queries) => {
|
||||||
updateUserById,
|
updateUserById,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
/* eslint-enable max-lines */
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
mockUserTotpMfaVerification,
|
mockUserTotpMfaVerification,
|
||||||
mockUserWithMfaVerifications,
|
mockUserWithMfaVerifications,
|
||||||
} from '#src/__mocks__/index.js';
|
} from '#src/__mocks__/index.js';
|
||||||
|
import { type InsertUserResult } from '#src/libraries/user.js';
|
||||||
import type Libraries from '#src/tenants/Libraries.js';
|
import type Libraries from '#src/tenants/Libraries.js';
|
||||||
import type Queries from '#src/tenants/Queries.js';
|
import type Queries from '#src/tenants/Queries.js';
|
||||||
import { MockTenant, type Partial2 } from '#src/test-utils/tenant.js';
|
import { MockTenant, type Partial2 } from '#src/test-utils/tenant.js';
|
||||||
|
@ -44,10 +45,13 @@ const mockLibraries = {
|
||||||
users: {
|
users: {
|
||||||
generateUserId: jest.fn(async () => 'fooId'),
|
generateUserId: jest.fn(async () => 'fooId'),
|
||||||
insertUser: jest.fn(
|
insertUser: jest.fn(
|
||||||
async (user: CreateUser): Promise<User> => ({
|
async (user: CreateUser): Promise<InsertUserResult> => [
|
||||||
...mockUser,
|
{
|
||||||
...removeUndefinedKeys(user), // No undefined values will be returned from database
|
...mockUser,
|
||||||
})
|
...removeUndefinedKeys(user), // No undefined values will be returned from database
|
||||||
|
},
|
||||||
|
{ organizationIds: [] },
|
||||||
|
]
|
||||||
),
|
),
|
||||||
updateUserById: jest.fn(
|
updateUserById: jest.fn(
|
||||||
async (_, data: Partial<CreateUser>): Promise<User> => ({
|
async (_, data: Partial<CreateUser>): Promise<User> => ({
|
||||||
|
|
Loading…
Reference in a new issue