@@ -7,16 +7,14 @@ import {
7
7
User ,
8
8
Restriction ,
9
9
Student ,
10
- Application ,
11
10
EducationProgramOffering ,
12
11
RestrictionActionType ,
13
12
} from "@sims/sims-db" ;
14
13
import { DataSource , EntityManager } from "typeorm" ;
15
14
import { CustomNamedError } from "@sims/utilities" ;
16
- import { RestrictionService } from "./restriction.service" ;
17
- import { RestrictionCode } from "./models/restriction.model" ;
18
15
import {
19
16
NoteSharedService ,
17
+ RestrictionCode ,
20
18
StudentRestrictionSharedService ,
21
19
} from "@sims/services" ;
22
20
export const RESTRICTION_NOT_ACTIVE = "RESTRICTION_NOT_ACTIVE" ;
@@ -29,9 +27,8 @@ export const RESTRICTION_NOT_PROVINCIAL = "RESTRICTION_NOT_PROVINCIAL";
29
27
export class StudentRestrictionService extends RecordDataModelService < StudentRestriction > {
30
28
constructor (
31
29
readonly dataSource : DataSource ,
32
- private readonly restrictionService : RestrictionService ,
33
30
private readonly noteSharedService : NoteSharedService ,
34
- private readonly studentRestrictionsService : StudentRestrictionSharedService ,
31
+ private readonly studentRestrictionSharedService : StudentRestrictionSharedService ,
35
32
) {
36
33
super ( dataSource . getRepository ( StudentRestriction ) ) ;
37
34
}
@@ -145,7 +142,7 @@ export class StudentRestrictionService extends RecordDataModelService<StudentRes
145
142
const newRestriction = await transactionalEntityManager
146
143
. getRepository ( StudentRestriction )
147
144
. save ( studentRestriction ) ;
148
- await this . studentRestrictionsService . createNotifications (
145
+ await this . studentRestrictionSharedService . createNotifications (
149
146
[ newRestriction . id ] ,
150
147
auditUserId ,
151
148
transactionalEntityManager ,
@@ -171,7 +168,7 @@ export class StudentRestrictionService extends RecordDataModelService<StudentRes
171
168
const studentRestrictionEntity = await this . repo . findOne ( {
172
169
where : {
173
170
id : studentRestrictionId ,
174
- student : { id : studentId } as Student ,
171
+ student : { id : studentId } ,
175
172
isActive : true ,
176
173
} ,
177
174
relations : { restriction : true } ,
@@ -228,7 +225,7 @@ export class StudentRestrictionService extends RecordDataModelService<StudentRes
228
225
restrictionActions : RestrictionActionType [ ] ,
229
226
checkAll = false ,
230
227
) : Promise < boolean > {
231
- const query = this . studentRestrictionsService
228
+ const query = this . studentRestrictionSharedService
232
229
. getExistsBlockRestrictionQuery ( checkAll , true )
233
230
. setParameters ( {
234
231
studentId,
@@ -262,38 +259,6 @@ export class StudentRestrictionService extends RecordDataModelService<StudentRes
262
259
. getOne ( ) ) ;
263
260
}
264
261
265
- /**
266
- * Create a new student restriction object.
267
- * @param studentId student id.
268
- * @param restrictionCode restriction code.
269
- * @param auditUserId audit user id
270
- * @param applicationId application id.
271
- * @returns a new student restriction object.
272
- */
273
- async createRestrictionToSave (
274
- studentId : number ,
275
- restrictionCode : RestrictionCode ,
276
- auditUserId : number ,
277
- applicationId : number ,
278
- ) : Promise < StudentRestriction > {
279
- const restriction = await this . restrictionService . getRestrictionByCode (
280
- restrictionCode ,
281
- ) ;
282
- if ( ! restriction ) {
283
- throw new Error (
284
- `Requested restriction code ${ restrictionCode } not found.` ,
285
- ) ;
286
- }
287
- const studentRestriction = new StudentRestriction ( ) ;
288
- studentRestriction . restriction = {
289
- id : restriction . id ,
290
- } as Restriction ;
291
- studentRestriction . student = { id : studentId } as Student ;
292
- studentRestriction . application = { id : applicationId } as Application ;
293
- studentRestriction . creator = { id : auditUserId } as User ;
294
- return studentRestriction ;
295
- }
296
-
297
262
/**
298
263
* Verify if the student has a valid SIN to apply to the particular offering.
299
264
* The SIN number must be a permanent one or a temporary with expiry date later
@@ -358,16 +323,17 @@ export class StudentRestrictionService extends RecordDataModelService<StudentRes
358
323
}
359
324
360
325
if ( mustCreateSINException ) {
361
- const restriction = await this . createRestrictionToSave (
362
- studentId ,
363
- RestrictionCode . SINF ,
364
- auditUserId ,
365
- applicationId ,
366
- ) ;
326
+ const restriction =
327
+ await this . studentRestrictionSharedService . createRestrictionToSave (
328
+ studentId ,
329
+ RestrictionCode . SINF ,
330
+ auditUserId ,
331
+ applicationId ,
332
+ ) ;
367
333
const newRestriction = await entityManager
368
334
. getRepository ( StudentRestriction )
369
335
. save ( restriction ) ;
370
- await this . studentRestrictionsService . createNotifications (
336
+ await this . studentRestrictionSharedService . createNotifications (
371
337
[ newRestriction . id ] ,
372
338
auditUserId ,
373
339
entityManager ,
0 commit comments