1
1
import { NotFoundError } from '~/libs/exceptions/exceptions.js' ;
2
2
import { type IService } from '~/libs/interfaces/interfaces.js' ;
3
3
import { HttpCode , HttpError , HttpMessage } from '~/libs/packages/http/http.js' ;
4
- import { type EntityPagination } from '~/libs/types/types.js' ;
4
+ import { type PaginationWithSortingParameters } from '~/libs/types/types.js' ;
5
5
import { UserGroupKey } from '~/packages/users/libs/enums/enums.js' ;
6
6
7
7
import { type DriverService } from '../drivers/driver.service.js' ;
@@ -12,7 +12,11 @@ import {
12
12
type DriverGetAllResponseDto ,
13
13
} from '../drivers/drivers.js' ;
14
14
import { type ShiftEntity } from '../shifts/shift.js' ;
15
- import { type TruckEntity } from '../trucks/libs/types/types.js' ;
15
+ import {
16
+ type TruckAddRequestDto ,
17
+ type TruckEntity ,
18
+ type TruckGetAllResponseDto ,
19
+ } from '../trucks/libs/types/types.js' ;
16
20
import { type TruckService } from '../trucks/truck.service.js' ;
17
21
import { type UserEntityT } from '../users/users.js' ;
18
22
import { BusinessEntity } from './business.entity.js' ;
@@ -211,23 +215,26 @@ class BusinessService implements IService {
211
215
return await this . driverService . delete ( driverId ) ;
212
216
}
213
217
214
- public checkisDriverBelongedToBusiness ( {
215
- userId,
216
- driverId,
217
- } : {
218
- userId : UserEntityT [ 'id' ] ;
219
- driverId : ShiftEntity [ 'driverId' ] ;
220
- } ) : Promise < boolean > {
221
- return this . businessRepository . checkisDriverBelongedToBusiness (
222
- userId ,
223
- driverId ,
224
- ) ;
218
+ public async findAllTrucksByBusinessId (
219
+ userId : number ,
220
+ query : PaginationWithSortingParameters ,
221
+ ) : Promise < TruckGetAllResponseDto > {
222
+ const business = await this . findByOwnerId ( userId ) ;
223
+
224
+ if ( ! business ) {
225
+ throw new HttpError ( {
226
+ status : HttpCode . BAD_REQUEST ,
227
+ message : HttpMessage . BUSINESS_DOES_NOT_EXIST ,
228
+ } ) ;
229
+ }
230
+
231
+ return await this . truckService . findAllByBusinessId ( business . id , query ) ;
225
232
}
226
233
227
- public async findAllTrucksByOwnerId (
234
+ public async createTruck (
235
+ payload : TruckAddRequestDto ,
228
236
userId : number ,
229
- query : GetPaginatedPageQuery ,
230
- ) : Promise < EntityPagination < TruckEntity > > {
237
+ ) : Promise < TruckEntity > {
231
238
const business = await this . findByOwnerId ( userId ) ;
232
239
233
240
if ( ! business ) {
@@ -237,7 +244,23 @@ class BusinessService implements IService {
237
244
} ) ;
238
245
}
239
246
240
- return await this . truckService . findAllByBusinessId ( business . id , query ) ;
247
+ return await this . truckService . create ( {
248
+ ...payload ,
249
+ businessId : business . id ,
250
+ } ) ;
251
+ }
252
+
253
+ public checkisDriverBelongedToBusiness ( {
254
+ userId,
255
+ driverId,
256
+ } : {
257
+ userId : UserEntityT [ 'id' ] ;
258
+ driverId : ShiftEntity [ 'driverId' ] ;
259
+ } ) : Promise < boolean > {
260
+ return this . businessRepository . checkisDriverBelongedToBusiness (
261
+ userId ,
262
+ driverId ,
263
+ ) ;
241
264
}
242
265
}
243
266
0 commit comments