diff --git a/dictation_server/src/constants/index.ts b/dictation_server/src/constants/index.ts index da502d7..511e4b8 100644 --- a/dictation_server/src/constants/index.ts +++ b/dictation_server/src/constants/index.ts @@ -88,6 +88,16 @@ export const USER_ROLES = { TYPIST: 'typist', } as const; +/** + * ロールのソート順 + * @const {string[]} + */ +export const USER_ROLE_ORDERS = [ + USER_ROLES.AUTHOR, + USER_ROLES.TYPIST, + USER_ROLES.NONE, +] as string[]; + /** * ライセンス注文状態 * @const {string[]} diff --git a/dictation_server/src/features/users/users.service.spec.ts b/dictation_server/src/features/users/users.service.spec.ts index 82a8199..a02016e 100644 --- a/dictation_server/src/features/users/users.service.spec.ts +++ b/dictation_server/src/features/users/users.service.spec.ts @@ -1,5 +1,4 @@ import { HttpException, HttpStatus } from '@nestjs/common'; -import { AccessToken } from '../../common/token'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; import { makeDefaultAdB2cMockValue, @@ -1389,6 +1388,16 @@ describe('UsersService.getUsers', () => { if (!module) fail(); const { id: accountId } = await makeTestSimpleAccount(source); + const { id: typistUserId } = await makeTestUser(source, { + account_id: accountId, + external_id: 'external_id2', + role: 'typist', + author_id: undefined, + auto_renew: true, + encryption: false, + encryption_password: undefined, + prompt: false, + }); const { external_id: externalId_author, id: authorUserId } = await makeTestUser(source, { account_id: accountId, @@ -1401,17 +1410,6 @@ describe('UsersService.getUsers', () => { prompt: false, }); - const { id: typistUserId } = await makeTestUser(source, { - account_id: accountId, - external_id: 'external_id2', - role: 'typist', - author_id: undefined, - auto_renew: true, - encryption: false, - encryption_password: undefined, - prompt: false, - }); - await createUserGroup(source, accountId, 'group1', [typistUserId]); const { id: noneUserId } = await makeTestUser(source, { diff --git a/dictation_server/src/repositories/users/users.repository.service.ts b/dictation_server/src/repositories/users/users.repository.service.ts index 9237bdd..ae3fccc 100644 --- a/dictation_server/src/repositories/users/users.repository.service.ts +++ b/dictation_server/src/repositories/users/users.repository.service.ts @@ -29,6 +29,7 @@ import { TIERS, TRIAL_LICENSE_ISSUE_NUM, USER_ROLES, + USER_ROLE_ORDERS, } from '../../constants'; import { License } from '../licenses/entity/license.entity'; import { NewTrialLicenseExpirationDate } from '../../features/licenses/types/types'; @@ -496,10 +497,23 @@ export class UsersRepositoryService { license: true, }, where: { account_id: accountId }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); - return dbUsers; + // RoleのAuthor、Typist、Noneの順に並び替える + const roleSortedUsers = dbUsers.sort((a, b) => { + // Roleが同じ場合はIDの昇順で並び替える + if (a.role === b.role) { + return a.id - b.id; + } + + return ( + USER_ROLE_ORDERS.indexOf(a.role) - USER_ROLE_ORDERS.indexOf(b.role) + ); + }); + + return roleSortedUsers; }); }