File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Projects/BooksLibrary/src
sql/sequelize/repositories Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 11import { RoleDto } from 'domain.types/role/role.dto' ;
22
33export interface IRoleRepo {
4+ search ( ) : Promise < RoleDto [ ] > ;
5+
46 create ( entity : any ) : Promise < RoleDto > ;
57
68 getById ( id : number ) : Promise < RoleDto > ;
Original file line number Diff line number Diff line change @@ -3,11 +3,21 @@ import { Logger } from 'common/logger';
33import { IRoleRepo } from 'database/repository.interfaces/user.role.repo.interface' ;
44import { RoleDto } from 'domain.types/role/role.dto' ;
55import { Roles } from 'domain.types/role/role.types' ;
6- import { Op } from 'sequelize/types' ;
76import { RoleMapper } from '../mapper/user.role.mapper' ;
87import Role from '../models/role.model' ;
98
109export class UserRoleRepo implements IRoleRepo {
10+ search = async ( ) : Promise < RoleDto [ ] > => {
11+ try {
12+ const role : Role [ ] = await Role . findAll ( ) ;
13+ const dto : RoleDto [ ] = role . map ( ( userRole ) => RoleMapper . toDto ( userRole ) ) ;
14+ return dto ;
15+ } catch ( error ) {
16+ Logger . instance ( ) . log ( error . message ) ;
17+ throw new ApiError ( 500 , error . message ) ;
18+ }
19+ } ;
20+
1121 create = async ( roleEntity : any ) : Promise < RoleDto > => {
1222 try {
1323 const entity = {
Original file line number Diff line number Diff line change 11import { Logger } from 'common/logger' ;
22import { IRoleRepo } from 'database/repository.interfaces/user.role.repo.interface' ;
3+ import { RoleDto } from 'domain.types/role/role.dto' ;
34import { Roles } from 'domain.types/role/role.types' ;
45import { inject , injectable } from 'tsyringe' ;
56
@@ -16,6 +17,11 @@ export class Seeder {
1617 } ;
1718
1819 seedDefaultRoles = async ( ) => {
20+ const existing : RoleDto [ ] = await this . _roleRepo . search ( ) ;
21+ if ( existing . length > 0 ) {
22+ return ;
23+ }
24+
1925 await this . _roleRepo . create ( {
2026 RoleName : Roles . Admin ,
2127 } ) ;
You can’t perform that action at this time.
0 commit comments