@@ -12,13 +12,32 @@ export class ScoresService {
12
12
private readonly scoreModel : Model < ScoreDocument >
13
13
) { }
14
14
15
+ async getLiveScores ( ) : Promise < any > {
16
+ try {
17
+ this . scoreModel . watch ( ) . on ( 'change' , ( data ) => {
18
+ console . log ( '\n ========================= \n' ) ;
19
+ console . log ( data ) ;
20
+ } ) ;
21
+
22
+ return this . scoreModel . find ( ) . sort ( 'order' ) . exec ( ) ;
23
+ // return await this.scoreModel.find().sort('order').exec();
24
+ } catch ( error ) {
25
+ throw new HttpException (
26
+ {
27
+ status : HttpStatus . FORBIDDEN ,
28
+ error : 'This is a custom exception message'
29
+ } ,
30
+ HttpStatus . FORBIDDEN
31
+ ) ;
32
+ }
33
+ }
15
34
async getScores ( ) {
16
35
try {
17
36
return this . scoreModel . find ( ) . sort ( 'order' ) . exec ( ) ;
18
37
19
38
// return await this.scoreModel.find().sort('order').exec();
20
39
} catch ( error ) {
21
- return new GraphQLError ( error ) ;
40
+ throw new HttpException ( 'Failed' , HttpStatus . EXPECTATION_FAILED ) ;
22
41
}
23
42
}
24
43
async getScore ( _id : string ) {
@@ -40,7 +59,7 @@ export class ScoresService {
40
59
. sort ( { batchID : - 1 } ) // sorts by "batchID: true" to the top
41
60
. exec ( ) ;
42
61
} catch ( error ) {
43
- return new GraphQLError ( error ) ;
62
+ throw new HttpException ( 'Failed' , HttpStatus . EXPECTATION_FAILED ) ;
44
63
}
45
64
}
46
65
async getActiveScores ( ) {
@@ -49,17 +68,35 @@ export class ScoresService {
49
68
inProgress : true
50
69
} ) ;
51
70
} catch ( error ) {
52
- return new GraphQLError ( error ) ;
71
+ throw new HttpException ( 'Failed' , HttpStatus . EXPECTATION_FAILED ) ;
53
72
}
54
73
}
55
74
75
+ async addRandomStuff ( tmcHostname : string ) {
76
+ const scoreGuid = tmcHostname ;
77
+ const batchID = tmcHostname ;
78
+ const score : Score = new Score ( { tmcHostname, scoreGuid, batchID } ) ;
79
+ score . startTime = new Date ( ) ;
80
+ try {
81
+ return await new this . scoreModel ( score ) . save ( ) ;
82
+ } catch ( error ) {
83
+ throw new HttpException ( error , HttpStatus . EXPECTATION_FAILED ) ;
84
+ }
85
+ }
86
+ async deleteRandomStuff ( name : string ) : Promise < any > {
87
+ try {
88
+ return await this . scoreModel . findOneAndDelete ( { tmcHostname : name } ) ;
89
+ } catch ( error ) {
90
+ throw new HttpException ( error , HttpStatus . EXPECTATION_FAILED ) ;
91
+ }
92
+ }
56
93
async scoreStart ( tmcHostname : string , scoreGuid : string , batchID : string ) {
57
94
const score : Score = new Score ( { tmcHostname, scoreGuid, batchID } ) ;
58
95
score . startTime = new Date ( ) ;
59
96
try {
60
97
return await new this . scoreModel ( score ) . save ( ) ;
61
98
} catch ( error ) {
62
- return new GraphQLError ( error ) ;
99
+ throw new HttpException ( 'Failed' , HttpStatus . EXPECTATION_FAILED ) ;
63
100
}
64
101
}
65
102
@@ -109,7 +146,7 @@ export class ScoresService {
109
146
return pd ;
110
147
} ) ;
111
148
} catch ( error ) {
112
- return new GraphQLError ( error ) ;
149
+ throw new HttpException ( 'Failed' , HttpStatus . EXPECTATION_FAILED ) ;
113
150
}
114
151
}
115
152
@@ -127,7 +164,7 @@ export class ScoresService {
127
164
} )
128
165
. exec ( ) ;
129
166
} catch ( error ) {
130
- return new GraphQLError ( error ) ;
167
+ throw new HttpException ( 'Failed' , HttpStatus . EXPECTATION_FAILED ) ;
131
168
}
132
169
}
133
170
0 commit comments