@@ -469,6 +469,7 @@ export class EmployeeService extends TenantAwareCrudService<Employee> {
469469
470470 // Tables joins with relations
471471 query . leftJoin ( `${ query . alias } .user` , 'user' ) ;
472+ query . leftJoin ( 'user.organizations' , 'userOrganization' ) ;
472473 query . leftJoin ( `${ query . alias } .tags` , 'tags' ) ;
473474 query . leftJoinAndSelect ( `${ query . alias } .organizationEmploymentTypes` , 'organizationEmploymentTypes' ) ;
474475
@@ -511,8 +512,9 @@ export class EmployeeService extends TenantAwareCrudService<Employee> {
511512 web . andWhere ( p ( `"${ qb . alias } "."tenantId" = :tenantId` ) , { tenantId } ) ;
512513
513514 if ( isNotEmpty ( where ?. organizationId ) ) {
514- const organizationId = where . organizationId ;
515- web . andWhere ( p ( `"${ qb . alias } "."organizationId" = :organizationId` ) , { organizationId } ) ;
515+ web . andWhere ( `"userOrganization"."organizationId" = :organizationId` , {
516+ organizationId : where . organizationId
517+ } ) ;
516518 }
517519 } )
518520 ) ;
@@ -699,4 +701,47 @@ export class EmployeeService extends TenantAwareCrudService<Employee> {
699701 return null ;
700702 }
701703 }
704+
705+ async findByIds ( employeeIds : string [ ] , options ?: FindManyOptions < Employee > ) : Promise < IEmployee [ ] > {
706+ try {
707+ if ( ! employeeIds . length ) {
708+ return [ ] ;
709+ }
710+
711+ const where = {
712+ id : In ( employeeIds ) ,
713+ isActive : true ,
714+ isArchived : false
715+ } ;
716+
717+ const queryOptions : FindManyOptions < Employee > = {
718+ ...options ,
719+ where : {
720+ ...where ,
721+ ...( options ?. where || { } )
722+ } ,
723+ relations : {
724+ user : true ,
725+ ...( options ?. relations || { } )
726+ }
727+ } ;
728+
729+ switch ( this . ormType ) {
730+ case MultiORMEnum . MikroORM : {
731+ const { where : mikroWhere , mikroOptions } = parseTypeORMFindToMikroOrm < Employee > ( queryOptions ) ;
732+ const employees = await this . mikroOrmRepository . find ( mikroWhere , mikroOptions ) ;
733+ return employees . map ( ( e ) => this . serialize ( e as Employee ) ) ;
734+ }
735+
736+ case MultiORMEnum . TypeORM :
737+ return await this . typeOrmRepository . find ( queryOptions ) ;
738+
739+ default :
740+ throw new Error ( `Not implemented for ORM type: ${ this . ormType } ` ) ;
741+ }
742+ } catch ( error ) {
743+ this . logger . error ( 'Error finding employees by IDs' , error ) ;
744+ return [ ] ;
745+ }
746+ }
702747}
0 commit comments