@@ -5,7 +5,10 @@ import {
55 CleaningAssignment ,
66 CleaningAssignmentStatus ,
77} from '../entity/cleaning-assignment.entity' ;
8- import { CleaningTrade , CleaningTradeStatus } from '../entity/cleaning-trade.entity' ;
8+ import {
9+ CleaningTrade ,
10+ CleaningTradeStatus ,
11+ } from '../entity/cleaning-trade.entity' ;
912import { CleaningScheduleStatus } from '../entity/cleaning-schedule.entity' ;
1013import { BusinessError , CleaningErrorCode } from '../../common/errors' ;
1114
@@ -51,9 +54,13 @@ export class CleaningTradeService {
5154 'res.name AS "resourceName"' ,
5255 ] )
5356 . where ( 'a.userId = :userId' , { userId } )
54- . andWhere ( 'a.status = :status' , { status : CleaningAssignmentStatus . ASSIGNED } )
57+ . andWhere ( 'a.status = :status' , {
58+ status : CleaningAssignmentStatus . ASSIGNED ,
59+ } )
5560 . andWhere ( 's.cleaningDate >= :today' , { today } )
56- . andWhere ( 's.status = :schedStatus' , { schedStatus : CleaningScheduleStatus . SCHEDULED } )
61+ . andWhere ( 's.status = :schedStatus' , {
62+ schedStatus : CleaningScheduleStatus . SCHEDULED ,
63+ } )
5764 . andWhere ( 'r.deletedAt IS NULL' )
5865 . orderBy ( 's.cleaningDate' , 'ASC' )
5966 . getRawMany < {
@@ -101,7 +108,11 @@ export class CleaningTradeService {
101108 . select ( 't.id' )
102109 . getRawMany < { t_id : number } > ( ) ;
103110
104- const result : { trade : { id : number } ; myAssignment : AssignmentDetail ; targetAssignment : AssignmentDetail } [ ] = [ ] ;
111+ const result : {
112+ trade : { id : number } ;
113+ myAssignment : AssignmentDetail ;
114+ targetAssignment : AssignmentDetail ;
115+ } [ ] = [ ] ;
105116 for ( const { t_id } of trades ) {
106117 const detail = await this . getTradeWithDetails ( t_id ) ;
107118 if ( detail )
@@ -131,18 +142,28 @@ export class CleaningTradeService {
131142 . createQueryBuilder ( 'a' )
132143 . select ( 'a.userId' , 'userId' )
133144 . where ( 'a.scheduleId = :schedId' , { schedId : myAssignment . scheduleId } )
134- . andWhere ( 'a.status != :canceled' , { canceled : CleaningAssignmentStatus . CANCELED } )
145+ . andWhere ( 'a.status != :canceled' , {
146+ canceled : CleaningAssignmentStatus . CANCELED ,
147+ } )
135148 . getRawMany < { userId : number } > ( ) ;
136- const myScheduleUserIds = new Set ( myScheduleUsers . map ( ( r ) => Number ( r . userId ) ) ) ;
149+ const myScheduleUserIds = new Set (
150+ myScheduleUsers . map ( ( r ) => Number ( r . userId ) ) ,
151+ ) ;
137152
138153 // 이미 처리 대기 중인 배정은 중복 교환 요청을 막기 위해 후보에서 제외한다.
139154 const pendingTrades = await this . tradeRepo
140155 . createQueryBuilder ( 't' )
141156 . select ( [ 't.requesterAssignmentId' , 't.targetAssignmentId' ] )
142157 . where ( 't.status = :status' , { status : CleaningTradeStatus . PENDING } )
143- . getRawMany < { t_requesterAssignmentId : number ; t_targetAssignmentId : number } > ( ) ;
158+ . getRawMany < {
159+ t_requesterAssignmentId : number ;
160+ t_targetAssignmentId : number ;
161+ } > ( ) ;
144162 const pendingIds = new Set < number > ( ) ;
145- for ( const { t_requesterAssignmentId, t_targetAssignmentId } of pendingTrades ) {
163+ for ( const {
164+ t_requesterAssignmentId,
165+ t_targetAssignmentId,
166+ } of pendingTrades ) {
146167 pendingIds . add ( Number ( t_requesterAssignmentId ) ) ;
147168 pendingIds . add ( Number ( t_targetAssignmentId ) ) ;
148169 }
@@ -164,10 +185,16 @@ export class CleaningTradeService {
164185 's.cleaningDate AS "cleaningDate"' ,
165186 'res.name AS "resourceName"' ,
166187 ] )
167- . where ( 'a.status = :status' , { status : CleaningAssignmentStatus . ASSIGNED } )
168- . andWhere ( 'a.scheduleId != :mySchedule' , { mySchedule : myAssignment . scheduleId } )
188+ . where ( 'a.status = :status' , {
189+ status : CleaningAssignmentStatus . ASSIGNED ,
190+ } )
191+ . andWhere ( 'a.scheduleId != :mySchedule' , {
192+ mySchedule : myAssignment . scheduleId ,
193+ } )
169194 . andWhere ( 's.cleaningDate >= :today' , { today } )
170- . andWhere ( 's.status = :schedStatus' , { schedStatus : CleaningScheduleStatus . SCHEDULED } )
195+ . andWhere ( 's.status = :schedStatus' , {
196+ schedStatus : CleaningScheduleStatus . SCHEDULED ,
197+ } )
171198 . andWhere ( 'r.deletedAt IS NULL' )
172199 . orderBy ( 's.cleaningDate' , 'ASC' )
173200 . getRawMany < {
@@ -212,7 +239,8 @@ export class CleaningTradeService {
212239 status : CleaningTradeStatus . PENDING ,
213240 } ,
214241 } ) ;
215- if ( existing ) throw new BusinessError ( CleaningErrorCode . TRADE_ALREADY_PENDING ) ;
242+ if ( existing )
243+ throw new BusinessError ( CleaningErrorCode . TRADE_ALREADY_PENDING ) ;
216244
217245 return this . tradeRepo . save (
218246 this . tradeRepo . create ( {
@@ -242,15 +270,19 @@ export class CleaningTradeService {
242270 throw new BusinessError ( CleaningErrorCode . TRADE_FORBIDDEN ) ;
243271
244272 if ( ! accept ) {
245- await this . tradeRepo . update ( tradeId , { status : CleaningTradeStatus . REJECTED } ) ;
273+ await this . tradeRepo . update ( tradeId , {
274+ status : CleaningTradeStatus . REJECTED ,
275+ } ) ;
246276 return ;
247277 }
248278
249279 await this . swapAssignments (
250280 trade . requesterAssignmentId ,
251281 trade . targetAssignmentId ,
252282 ) ;
253- await this . tradeRepo . update ( tradeId , { status : CleaningTradeStatus . ACCEPTED } ) ;
283+ await this . tradeRepo . update ( tradeId , {
284+ status : CleaningTradeStatus . ACCEPTED ,
285+ } ) ;
254286 }
255287
256288 // 두 배정의 담당자를 바꾸기 전에 같은 일정/중복 담당자 충돌을 먼저 막는다.
@@ -259,7 +291,8 @@ export class CleaningTradeService {
259291 this . assignmentRepo . findOne ( { where : { id : id1 } } ) ,
260292 this . assignmentRepo . findOne ( { where : { id : id2 } } ) ,
261293 ] ) ;
262- if ( ! a1 || ! a2 ) throw new BusinessError ( CleaningErrorCode . ASSIGNMENT_NOT_FOUND ) ;
294+ if ( ! a1 || ! a2 )
295+ throw new BusinessError ( CleaningErrorCode . ASSIGNMENT_NOT_FOUND ) ;
263296 if (
264297 a1 . status !== CleaningAssignmentStatus . ASSIGNED ||
265298 a2 . status !== CleaningAssignmentStatus . ASSIGNED
@@ -366,9 +399,13 @@ export class CleaningTradeService {
366399 'res.name AS "resourceName"' ,
367400 ] )
368401 . where ( 's.ruleId = :ruleId' , { ruleId } )
369- . andWhere ( 'a.status = :status' , { status : CleaningAssignmentStatus . ASSIGNED } )
402+ . andWhere ( 'a.status = :status' , {
403+ status : CleaningAssignmentStatus . ASSIGNED ,
404+ } )
370405 . andWhere ( 's.cleaningDate >= :today' , { today } )
371- . andWhere ( 's.status = :schedStatus' , { schedStatus : CleaningScheduleStatus . SCHEDULED } )
406+ . andWhere ( 's.status = :schedStatus' , {
407+ schedStatus : CleaningScheduleStatus . SCHEDULED ,
408+ } )
372409 . orderBy ( 's.cleaningDate' , 'ASC' )
373410 . getRawMany < {
374411 id : number ;
@@ -419,7 +456,9 @@ export class CleaningTradeService {
419456 if ( ! requester || requester . userId !== userId )
420457 throw new BusinessError ( CleaningErrorCode . TRADE_FORBIDDEN ) ;
421458
422- await this . tradeRepo . update ( tradeId , { status : CleaningTradeStatus . CANCELED } ) ;
459+ await this . tradeRepo . update ( tradeId , {
460+ status : CleaningTradeStatus . CANCELED ,
461+ } ) ;
423462 }
424463
425464 private async getCoAssigneeNames (
@@ -432,7 +471,9 @@ export class CleaningTradeService {
432471 . select ( 'u.name' , 'name' )
433472 . where ( 'a.scheduleId = :scheduleId' , { scheduleId } )
434473 . andWhere ( 'a.userId != :excludeUserId' , { excludeUserId } )
435- . andWhere ( 'a.status = :status' , { status : CleaningAssignmentStatus . ASSIGNED } )
474+ . andWhere ( 'a.status = :status' , {
475+ status : CleaningAssignmentStatus . ASSIGNED ,
476+ } )
436477 . getRawMany < { name : string } > ( ) ;
437478 return rows . map ( ( r ) => r . name ) ;
438479 }
0 commit comments