File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -46,11 +46,22 @@ export class UpdateTimerInput {
46
46
@IsDate ( )
47
47
date : Date ;
48
48
49
- @Field ( ( ) => Date , { nullable : false } )
49
+ @Field ( ( ) => Date , { nullable : true } )
50
50
@IsDate ( )
51
51
time : Date ;
52
52
53
53
@Field ( ( ) => String , { nullable : true } )
54
54
@IsString ( )
55
55
status : string ;
56
56
}
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
+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { TimerService } from "./timer.service";
3
3
import { TimerResponse , TimersResponse } from "./entities/timer.entity" ;
4
4
import { JwtAuthGuard } from "../../guards/auth/auth.guard" ;
5
5
import { UseGuards } from "@nestjs/common" ;
6
- import { CreateTimerInput , UpdateTimerInput } from "./dto/timer.input" ;
6
+ import { CreateTimerInput , UpdateTimerInput , UpdateTimerStatusInput } from "./dto/timer.input" ;
7
7
8
8
@Resolver ( )
9
9
export class TimerResolver {
@@ -28,6 +28,12 @@ export class TimerResolver {
28
28
return this . timerService . updateTimer ( input ) ;
29
29
}
30
30
31
+ @Mutation ( ( ) => TimerResponse )
32
+ @UseGuards ( JwtAuthGuard )
33
+ async update_timer_status ( @Args ( "input" ) input : UpdateTimerStatusInput ) {
34
+ return this . timerService . updateTimerStatus ( input ) ;
35
+ }
36
+
31
37
@Mutation ( ( ) => String )
32
38
@UseGuards ( JwtAuthGuard )
33
39
async delete_timer ( @Args ( "timerID" ) timerID : number ) {
Original file line number Diff line number Diff line change 1
1
import { Injectable } from "@nestjs/common" ;
2
2
import { GraphQLError } from "graphql" ;
3
3
import { PrismaService } from "../prisma/prisma.service" ;
4
- import { CreateTimerInput , UpdateTimerInput } from "./dto/timer.input" ;
4
+ import { CreateTimerInput , UpdateTimerInput , UpdateTimerStatusInput } from "./dto/timer.input" ;
5
5
6
6
@Injectable ( )
7
7
export class TimerService {
@@ -36,6 +36,7 @@ export class TimerService {
36
36
action : input . action ,
37
37
date : input ?. date ,
38
38
time : input ?. time ,
39
+ status : input ?. status ,
39
40
} ,
40
41
} ) ;
41
42
if ( newData ) {
@@ -63,6 +64,7 @@ export class TimerService {
63
64
time : input ?. time ,
64
65
date : input ?. date ,
65
66
deviceID : input ?. deviceID ,
67
+ status : input ?. status ,
66
68
} ,
67
69
} ) ;
68
70
if ( updateData ) {
@@ -77,6 +79,23 @@ export class TimerService {
77
79
}
78
80
}
79
81
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
+
80
99
async deleteTimer ( timerID : number ) {
81
100
try {
82
101
const data = await this . prisma . timer . delete ( {
You can’t perform that action at this time.
0 commit comments