This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implements submit survey pages
- Loading branch information
1 parent
79e8a9c
commit 71cc6e3
Showing
25 changed files
with
1,002 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,93 @@ | ||
import { Service } from '@libs/decorator' | ||
import { EntityNotExistException, UnexpectedException } from '@libs/exception' | ||
import { PrismaService } from '@libs/prisma' | ||
import { calculatePaginationOffset } from '@libs/utils' | ||
import { Prisma } from '@prisma/client' | ||
import type { | ||
AttendanceWithRoster, | ||
CreateAttendanceDTO | ||
} from './dto/attendance.dto' | ||
|
||
@Service() | ||
export class AttendanceService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async createAttendances( | ||
rosterId: number, | ||
attendances: CreateAttendanceDTO[] | ||
): Promise<{ count: number }> { | ||
try { | ||
const attendancesWithRosterId = attendances.map((attendance) => { | ||
return { | ||
...attendance, | ||
rosterId | ||
} | ||
}) | ||
return await this.prisma.attendance.createMany({ | ||
data: attendancesWithRosterId | ||
}) | ||
} catch (error) { | ||
if ( | ||
error instanceof Prisma.PrismaClientKnownRequestError && | ||
error.code === 'P2003' | ||
) { | ||
throw new EntityNotExistException('로스터가 존재하지 않습니다') | ||
} | ||
throw new UnexpectedException(error) | ||
} | ||
} | ||
|
||
async getAttendances( | ||
scheduleId: number, | ||
searchTerm: string, | ||
page: number, | ||
limit = 10 | ||
): Promise<{ attendances: AttendanceWithRoster[] }> { | ||
try { | ||
const attendances = await this.prisma.attendance.findMany({ | ||
where: { | ||
scheduleId, | ||
Roster: { | ||
OR: [ | ||
{ | ||
offPosition: { | ||
contains: searchTerm | ||
}, | ||
defPosition: { | ||
contains: searchTerm | ||
}, | ||
splPosition: { | ||
contains: searchTerm | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
include: { | ||
Roster: { | ||
select: { | ||
id: true, | ||
name: true, | ||
type: true, | ||
registerYear: true, | ||
offPosition: true, | ||
defPosition: true, | ||
splPosition: true | ||
} | ||
} | ||
}, | ||
take: limit, | ||
skip: calculatePaginationOffset(page, limit), | ||
orderBy: { | ||
Roster: { | ||
name: 'asc' | ||
} | ||
} | ||
}) | ||
|
||
return { attendances } | ||
} catch (error) { | ||
throw new UnexpectedException(error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { | ||
AttendanceLocation, | ||
AttendanceResponse, | ||
type Attendance, | ||
type RosterType | ||
} from '@prisma/client' | ||
import { | ||
IsEnum, | ||
IsNotEmpty, | ||
IsNumber, | ||
IsOptional, | ||
IsString | ||
} from 'class-validator' | ||
|
||
export class CreateAttendanceDTO { | ||
@IsNumber() | ||
@IsNotEmpty() | ||
scheduleId: number | ||
|
||
@IsEnum(AttendanceResponse) | ||
@IsNotEmpty() | ||
response: AttendanceResponse | ||
|
||
@IsString() | ||
@IsOptional() | ||
reason?: string | ||
|
||
@IsEnum(AttendanceLocation) | ||
@IsOptional() | ||
location?: AttendanceLocation | ||
} | ||
|
||
export class UpdateAttendanceDTO { | ||
@IsEnum(AttendanceResponse) | ||
@IsOptional() | ||
response: AttendanceResponse | ||
|
||
@IsString() | ||
@IsOptional() | ||
reason?: string | ||
|
||
@IsEnum(AttendanceLocation) | ||
@IsOptional() | ||
location?: AttendanceLocation | ||
|
||
@IsEnum(AttendanceResponse) | ||
@IsOptional() | ||
result: AttendanceResponse | ||
} | ||
|
||
export interface AttendanceWithRoster extends Attendance { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
Roster: { | ||
id: number | ||
name: string | ||
type: RosterType | ||
registerYear: number | ||
offPosition?: string | ||
defPosition?: string | ||
splPosition?: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.