开发应用程序时,我在attendance.service.ts
中遇到以下错误
我查找了原因。但是现在我不知道了。
错误的地方在哪里?
src/attendance/attendance.service.ts:30:7 - error TS2740: Type 'AttendanceRequest' is missing the following properties from type 'Attendance': id, comeHometime, memo, hasId, and 5 more.
30 return attendanceParam;
~~~~~~~~~~~~~~~~~~~~~~~
[6:08:15 AM] Found 1 error. Watching for file changes.
以下是我目前的工作。如果有人有意见,请告诉我。
谢谢
attendance.service.ts
async updateEvent(
id: number,
attendanceParam: AttendanceRequest,
): Promise<Attendance> {
const origin = await this.attendanceRepository.findOne(id);
const updateData = Object.assign(origin, attendanceParam);
this.attendanceRepository.save(updateData);
return attendanceParam;
}
attendance.dto.ts
import {
IsEmail,
IsIn,
IsNotEmpty,
IsOptional,
MaxLength,
MinLength,
IsInt,
IsString,
IsDateString,
IsBooleanString,
IsBoolean,
Matches,
IsDefined,
isNotEmpty,
} from 'class-validator';
const dateRegex = /^(19[0-9]{2}|20[0-9]{2})-([1-9]|1[0-2])-([1-9]|[12][0-9]|3[01])$/;
const timeRegex = /^([01][0-9]|2[0-3]):[0-5][0-9]$/;
export class AttendanceRequest {
@IsNotEmpty()
@IsInt()
childId: number;
@IsNotEmpty()
@IsString()
attendanceCd: number;
@IsNotEmpty()
@IsString()
@Matches(timeRegex, {
message: `beginTime must match the format HH:MM`,
})
comehomeTime: string;
@IsNotEmpty()
@IsString()
@Matches(timeRegex, {
message: `beginTime must match the format HH:MM`,
})
lastTime: string;
@IsOptional()
@IsString()
detail: string;
createdAt: Date;
updatedAt: Date;
deletedAt: Date;
}