Skip to content

Commit 2be0090

Browse files
committed
fix/timer
1 parent 1d0b951 commit 2be0090

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/modules/timer/dto/timer.input.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,22 @@ export class UpdateTimerInput {
4646
@IsDate()
4747
date: Date;
4848

49-
@Field(() => Date, { nullable: false })
49+
@Field(() => Date, { nullable: true })
5050
@IsDate()
5151
time: Date;
5252

5353
@Field(() => String, { nullable: true })
5454
@IsString()
5555
status: string;
5656
}
57+
58+
@InputType()
59+
export class UpdateTimerStatusInput {
60+
@Field(() => Number, { nullable: false })
61+
@IsNumber()
62+
id: number;
63+
64+
@Field(() => String, { nullable: true })
65+
@IsString()
66+
status: string;
67+
}

src/modules/timer/timer.resolver.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TimerService } from "./timer.service";
33
import { TimerResponse, TimersResponse } from "./entities/timer.entity";
44
import { JwtAuthGuard } from "../../guards/auth/auth.guard";
55
import { UseGuards } from "@nestjs/common";
6-
import { CreateTimerInput, UpdateTimerInput } from "./dto/timer.input";
6+
import { CreateTimerInput, UpdateTimerInput, UpdateTimerStatusInput } from "./dto/timer.input";
77

88
@Resolver()
99
export class TimerResolver {
@@ -28,6 +28,12 @@ export class TimerResolver {
2828
return this.timerService.updateTimer(input);
2929
}
3030

31+
@Mutation(() => TimerResponse)
32+
@UseGuards(JwtAuthGuard)
33+
async update_timer_status(@Args("input") input: UpdateTimerStatusInput) {
34+
return this.timerService.updateTimerStatus(input);
35+
}
36+
3137
@Mutation(() => String)
3238
@UseGuards(JwtAuthGuard)
3339
async delete_timer(@Args("timerID") timerID: number) {

src/modules/timer/timer.service.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from "@nestjs/common";
22
import { GraphQLError } from "graphql";
33
import { PrismaService } from "../prisma/prisma.service";
4-
import { CreateTimerInput, UpdateTimerInput } from "./dto/timer.input";
4+
import { CreateTimerInput, UpdateTimerInput, UpdateTimerStatusInput } from "./dto/timer.input";
55

66
@Injectable()
77
export class TimerService {
@@ -36,6 +36,7 @@ export class TimerService {
3636
action: input.action,
3737
date: input?.date,
3838
time: input?.time,
39+
status: input?.status,
3940
},
4041
});
4142
if (newData) {
@@ -63,6 +64,7 @@ export class TimerService {
6364
time: input?.time,
6465
date: input?.date,
6566
deviceID: input?.deviceID,
67+
status: input?.status,
6668
},
6769
});
6870
if (updateData) {
@@ -77,6 +79,23 @@ export class TimerService {
7779
}
7880
}
7981

82+
async updateTimerStatus(input: UpdateTimerStatusInput) {
83+
try {
84+
const updateData = await this.prisma.timer.update({
85+
where: { id: input.id },
86+
data: {
87+
status: input?.status,
88+
},
89+
});
90+
if (updateData) {
91+
return updateData;
92+
}
93+
throw new GraphQLError("Cannot update timer!");
94+
} catch (err) {
95+
throw new GraphQLError(err);
96+
}
97+
}
98+
8099
async deleteTimer(timerID: number) {
81100
try {
82101
const data = await this.prisma.timer.delete({

0 commit comments

Comments
 (0)