36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import { BadRequestException, Body, Controller, Delete, Param, Patch, Post } from "@nestjs/common";
|
|
import { CreateShiftResult, UpdateShiftResult } from "src/time-and-attendance/utils/type.utils";
|
|
import { ShiftsUpsertService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service";
|
|
import { UpdateShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto";
|
|
import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto";
|
|
|
|
|
|
@Controller('shift')
|
|
export class ShiftController {
|
|
constructor( private readonly upsert_service: ShiftsUpsertService ){}
|
|
|
|
@Post('create')
|
|
createBatch(
|
|
@Body()dtos: ShiftDto[]): Promise<CreateShiftResult[]> {
|
|
const list = Array.isArray(dtos) ? dtos : [];
|
|
if(list.length === 0) throw new BadRequestException('Body is missing or invalid (create shifts)');
|
|
return this.upsert_service.createShifts(dtos)
|
|
}
|
|
|
|
|
|
//change Body to receive dtos
|
|
@Patch('update')
|
|
updateBatch(
|
|
@Body() dtos: UpdateShiftDto[]): Promise<UpdateShiftResult[]>{
|
|
const list = Array.isArray(dtos) ? dtos: [];
|
|
if(list.length === 0) throw new BadRequestException('Body is missing or invalid (update shifts)');
|
|
return this.upsert_service.updateShifts(dtos);
|
|
}
|
|
|
|
@Delete(':shift_id')
|
|
remove(@Param('shift_id') shift_id: number ) {
|
|
return this.upsert_service.deleteShift(shift_id);
|
|
}
|
|
|
|
}
|