@universis/accommodation 1.1.2 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@
5
5
  "title": "StudentAccommodationCard",
6
6
  "hidden": false,
7
7
  "sealed": false,
8
- "version": "1.5",
8
+ "version": "1.9",
9
9
  "source": "StudentAccommodationCardBase",
10
10
  "view": "StudentAccommodationCardData",
11
11
  "classPath": "./models/StudentAccommodationCard",
@@ -16,14 +16,14 @@
16
16
  "description": "Ο κωδικός της εγγραφής",
17
17
  "type": "Counter",
18
18
  "primary": true
19
- },
19
+ },
20
20
  {
21
21
  "name": "action",
22
22
  "title": "Action",
23
23
  "description": "The action associated with this card.",
24
24
  "type": "AccommodationRequestAction",
25
25
  "nullable": false
26
- },
26
+ },
27
27
  {
28
28
  "name": "student",
29
29
  "title": "Φοιτητής",
@@ -47,80 +47,75 @@
47
47
  "type": "AcademicYear",
48
48
  "expandable": true,
49
49
  "nullable": false
50
- },
51
-
52
- {
53
- "name": "serialNumber",
54
- "title": "Number",
55
- "type": "Integer",
56
- "nullable": false,
57
- "value": "javascript:return this.newid();"
58
- },
59
- {
60
- "name": "dateCreated",
61
- "title": "Date Created",
62
- "description": "The date on which this item was created.",
63
- "type": "DateTime",
64
- "value": "javascript:return (new Date());",
65
- "readonly": true
66
- },
67
- {
68
- "@id": "http://schema.org/validFrom",
69
- "name": "validFrom",
70
- "title": "validFrom",
71
- "description": "The date when the item becomes valid.",
72
- "type": "DateTime",
73
- "nullable": false
74
- },
75
- {
76
- "@id": "http://schema.org/validThrough",
77
- "name": "validThrough",
78
- "title": "validThrough",
79
- "description": "The date after when the item is not valid.",
80
- "type": "DateTime",
81
- "nullable": false
82
- },
83
- {
84
- "@id": "http://schema.org/cardStatus",
85
- "name": "cardStatus",
86
- "title": "cardStatus",
87
- "description": "Indicates the current disposition of the Card.",
88
- "type": "ActionStatusType",
89
- "value": "javascript:return { alternateName:'PotentialActionStatus' };"
90
- },
91
- {
92
- "name": "dateCancelled",
93
- "title": "Date Cancelled",
94
- "description": "The date on which this item was cancelled.",
95
- "type": "DateTime",
96
- "nullable": true
97
- },
98
- {
99
- "name": "cancelReason",
100
- "title": "Λόγοι ακύρωσης",
101
- "description": "Λόγοι ακύρωσης",
102
- "type": "Text",
103
- "size": 255,
104
- "many": false,
105
- "nullable": true
106
- },
107
- {
108
- "name": "dateModified",
109
- "title": "Ημερομηνία τροποποίησης",
110
- "description": "Ημερομηνία τροποποίησης",
111
- "type": "DateTime",
112
- "nullable": false,
113
- "value": "javascript:return new Date();",
114
- "calculation": "javascript:return this.now();"
115
- }
116
- ],
117
- "constraints": [
50
+ },
51
+ {
52
+ "name": "serialNumber",
53
+ "title": "Number",
54
+ "type": "Integer",
55
+ "nullable": false,
56
+ "value": "javascript:return this.newid();"
57
+ },
118
58
  {
119
- "type": "unique",
120
- "fields": [
121
- "student",
122
- "academicYear"
123
- ]
59
+ "name": "dateCreated",
60
+ "title": "Date Created",
61
+ "description": "The date on which this item was created.",
62
+ "type": "DateTime",
63
+ "value": "javascript:return (new Date());",
64
+ "readonly": true
65
+ },
66
+ {
67
+ "@id": "http://schema.org/validFrom",
68
+ "name": "validFrom",
69
+ "title": "validFrom",
70
+ "description": "The date when the item becomes valid.",
71
+ "type": "DateTime",
72
+ "nullable": false
73
+ },
74
+ {
75
+ "@id": "http://schema.org/validThrough",
76
+ "name": "validThrough",
77
+ "title": "validThrough",
78
+ "description": "The date after when the item is not valid.",
79
+ "type": "DateTime",
80
+ "nullable": false
81
+ },
82
+ {
83
+ "@id": "http://schema.org/cardStatus",
84
+ "name": "cardStatus",
85
+ "title": "cardStatus",
86
+ "description": "Indicates the current disposition of the Card.",
87
+ "type": "ActionStatusType",
88
+ "value": "javascript:return { alternateName:'PotentialActionStatus' };"
89
+ },
90
+ {
91
+ "name": "dateCancelled",
92
+ "title": "Date Cancelled",
93
+ "description": "The date on which this item was cancelled.",
94
+ "type": "DateTime",
95
+ "nullable": true
96
+ },
97
+ {
98
+ "name": "cancelReason",
99
+ "title": "Λόγοι ακύρωσης",
100
+ "description": "Λόγοι ακύρωσης",
101
+ "type": "Text",
102
+ "size": 255,
103
+ "many": false,
104
+ "nullable": true
105
+ },
106
+ {
107
+ "name": "dateModified",
108
+ "title": "Ημερομηνία τροποποίησης",
109
+ "description": "Ημερομηνία τροποποίησης",
110
+ "type": "DateTime",
111
+ "nullable": false,
112
+ "value": "javascript:return new Date();",
113
+ "calculation": "javascript:return this.now();"
114
+ },
115
+ {
116
+ "name": "isActive",
117
+ "readonly": true,
118
+ "virtual": true
124
119
  }
125
120
  ],
126
121
  "privileges": [
@@ -143,7 +138,7 @@
143
138
  "type": "self",
144
139
  "account": "Students",
145
140
  "filter": "student/user eq me()"
146
- }
141
+ }
147
142
  ],
148
143
  "eventListeners": [
149
144
  {
@@ -159,5 +154,4 @@
159
154
  "type": "./listeners/SendEmailAfterCardStatusChangeListener"
160
155
  }
161
156
  ]
162
- }
163
-
157
+ }
@@ -258,6 +258,42 @@
258
258
  'read',
259
259
  'write']
260
260
 
261
+ },
262
+ {
263
+ 'scope': [
264
+ 'accommodation'],
265
+
266
+ 'resource': '/api/RoomTypes',
267
+ 'access': [
268
+ 'read']
269
+
270
+ },
271
+ {
272
+ 'scope': [
273
+ 'accommodation'],
274
+
275
+ 'resource': '/api/Genders',
276
+ 'access': [
277
+ 'read']
278
+
279
+ },
280
+ {
281
+ 'scope': [
282
+ 'accommodation'],
283
+
284
+ 'resource': '/api/Regions',
285
+ 'access': [
286
+ 'read']
287
+
288
+ },
289
+ {
290
+ 'scope': [
291
+ 'accommodation'],
292
+
293
+ 'resource': '/api/Countries',
294
+ 'access': [
295
+ 'read']
296
+
261
297
  },
262
298
  {
263
299
  'scope': [
@@ -282,7 +318,7 @@
282
318
  'scope': [
283
319
  'students'],
284
320
 
285
- 'resource': '/api/Accommodations/?$',
321
+ 'resource': '/api/AccommodationPlaces/?$',
286
322
  'access': [
287
323
  'read']
288
324
 
@@ -1 +1 @@
1
- {"version":3,"file":"scope.access.js","names":["exports","default","_default"],"sources":["../../src/config/scope.access.js"],"sourcesContent":["export default [\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/users/me',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/content/private',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/ActionStatusTypes',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/StudentStatuses',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/StudentCategories',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/FamilyStatuses',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/LocalDepartments',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/EventStatusTypes',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/JsonAttachments',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'registrar',\n 'accommodation'\n ],\n 'resource': '/api/AccommodationInscriptionModeTags',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestActions',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/SpecialAccommodationRequestActions',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestActionMessages',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestActionReviews',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestAttachmentConfigurations',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'registrar',\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestEffectiveStatusTypes',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestEvents',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AcademicYears',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AcademicPeriods',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/StudentAccommodationCards',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationPlaces',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRooms',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationConfigurations',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/ReportTemplates',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestCategories',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestPreferences',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/UpdateAccommodationRequestEventActions',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/Institutes',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/TestActions/?$',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/Accommodations/?$',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/AccommodationRequestActions',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/AccommodationRequestEvents',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/AccommodationRequestCategories',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/StudentAccommodationCards',\n 'access': [\n 'read'\n ]\n }\n]\n"],"mappings":"mHAAe;AACX;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,eAAe;EAC3B,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,sBAAsB;EAClC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,wBAAwB;EACpC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,sBAAsB;EAClC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,wBAAwB;EACpC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,qBAAqB;EACjC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,uBAAuB;EACnC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAA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AAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,qBAAqB;EACjC,QAAQ,EAAE;EACN,MAAM;EACN,OAAO;;AAEf,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,wBAAwB;EACpC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,kCAAkC;EAC9C,QAAQ,EAAE;EACN,MAAM;EACN,OAAO;;AAEf,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,iCAAiC;EAC7C,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,qCAAqC;EACjD,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,gCAAgC;EAC5C,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC,CACJ,CAAAA,OAAA,CAAAC,OAAA,GAAAC,QAAA"}
1
+ {"version":3,"file":"scope.access.js","names":["exports","default","_default"],"sources":["../../src/config/scope.access.js"],"sourcesContent":["export default [\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/users/me',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/content/private',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/ActionStatusTypes',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/StudentStatuses',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/StudentCategories',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/FamilyStatuses',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/LocalDepartments',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/EventStatusTypes',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/JsonAttachments',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'registrar',\n 'accommodation'\n ],\n 'resource': '/api/AccommodationInscriptionModeTags',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestActions',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/SpecialAccommodationRequestActions',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestActionMessages',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestActionReviews',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestAttachmentConfigurations',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'registrar',\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestEffectiveStatusTypes',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestEvents',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AcademicYears',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AcademicPeriods',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/StudentAccommodationCards',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationPlaces',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRooms',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationConfigurations',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/ReportTemplates',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestCategories',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/AccommodationRequestPreferences',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/UpdateAccommodationRequestEventActions',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/RoomTypes',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/Genders',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/Regions',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/Countries',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'accommodation'\n ],\n 'resource': '/api/Institutes',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/TestActions/?$',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/AccommodationPlaces/?$',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/AccommodationRequestActions',\n 'access': [\n 'read',\n 'write'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/AccommodationRequestEvents',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/AccommodationRequestCategories',\n 'access': [\n 'read'\n ]\n },\n {\n 'scope': [\n 'students'\n ],\n 'resource': '/api/StudentAccommodationCards',\n 'access': [\n 'read'\n ]\n }\n]\n"],"mappings":"mHAAe;AACX;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,eAAe;EAC3B,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,sBAAsB;EAClC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,wBAAwB;EACpC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,sBAAsB;EAClC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,wBAAwB;EACpC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,qBAAqB;EACjC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,uBAAuB;EACnC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,uBAAuB;EACnC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,sBAAsB;EAClC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,WAAW;EACX,eAAe,CAClB;;E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AAE,gBAAgB;EAC5B,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,eAAe,CAClB;;EACD,UAAU,EAAE,iBAAiB;EAC7B,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,qBAAqB;EACjC,QAAQ,EAAE;EACN,MAAM;EACN,OAAO;;AAEf,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,6BAA6B;EACzC,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,kCAAkC;EAC9C,QAAQ,EAAE;EACN,MAAM;EACN,OAAO;;AAEf,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,iCAAiC;EAC7C,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,qCAAqC;EACjD,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC;AACD;EACI,OAAO,EAAE;EACL,UAAU,CACb;;EACD,UAAU,EAAE,gCAAgC;EAC5C,QAAQ,EAAE;EACN,MAAM;;AAEd,CAAC,CACJ,CAAAA,OAAA,CAAAC,OAAA,GAAAC,QAAA"}
@@ -13,17 +13,34 @@ var _common = require("@themost/common"); /**
13
13
  /**
14
14
  * @type {Student|DataObject|*}
15
15
  */
16
- const student = context.model('Student').convert(event.target.student);
17
- // const isActive = await student.silent().isActive();
16
+ const previous = event.previous;
17
+ let student = context.model('Student').convert(event.target.student);
18
+ if (!student) {
19
+ if (previous) {
20
+ student = context.model('Student').convert(previous.student);
21
+ } else {
22
+ throw new _common.DataError('ERR_STATUS', 'Student cannot be found');
23
+ }
24
+ }
18
25
  const isActive = await student.is(':active');
19
- if (!isActive) {
26
+
27
+ if (!isActive && event.state === 1)
28
+ {
20
29
  throw new _common.DataError('ERR_STATUS',
21
30
  'Invalid student status. Student Accommodation Card may be published upon an active student only.' + student,
22
31
  null,
23
32
  'Student', 'studentStatus');
24
33
  }
25
-
26
- const studentObject = await context.model('Student').where('id').equal(student.id).silent().flatten().getItem();
34
+ if (Object.prototype.hasOwnProperty.call(event.target, 'CardStatus')) {
35
+ const previousActionStatus = await context.model('ActionStatusType').find(previous.cardStatus).select('alternateName').value();
36
+ const targetActionStatus = await context.model('ActionStatusType').find(event.target.cardStatus).select('alternateName').value();
37
+ if (!isActive && previousActionStatus !== targetActionStatus && targetActionStatus !== 'CancelledActionStatus') {
38
+ throw new _common.DataError('ERR_STATUS',
39
+ 'The student accommodation card cannot be activated for an inactive student' + student,
40
+ null,
41
+ 'Student', 'studentStatus');
42
+ }
43
+ }
27
44
 
28
45
  const academicYear = context.model('AcademicYear').convert(event.target.academicYear).getId();
29
46
  if (Number.isInteger(academicYear) === false) {
@@ -1 +1 @@
1
- {"version":3,"file":"StudentAccommodationCardSaveListener.js","names":["_common","require","beforeSave","event","callback","state","context","model","student","convert","target","isActive","is","DataError","studentObject","where","equal","id","silent","flatten","getItem","academicYear","getId","Number","isInteger","academicYearObject","undefined","academicPeriod","academicPeriodObject","then","catch","err","afterSave","accommodationRoom","Object","keys","length","room","newRoom","currentOccupancy","save"],"sources":["../../src/listeners/StudentAccommodationCardSaveListener.js"],"sourcesContent":["/**\n * @param {DataEventArgs} event\n * @param {Function} callback\n */\nimport {DataError} from \"@themost/common\";\n\nexport function beforeSave(event, callback) {\n (async () => {\n\n // validate student state (on insert or update)\n if (event.state === 1 || event.state === 2) {\n let context = event.model.context;\n /**\n * @type {Student|DataObject|*}\n */\n const student = context.model('Student').convert(event.target.student);\n // const isActive = await student.silent().isActive();\n const isActive = await student.is(':active');\n if (!isActive) {\n throw new DataError('ERR_STATUS',\n 'Invalid student status. Student Accommodation Card may be published upon an active student only.'+student\n , null,\n 'Student', 'studentStatus');\n }\n \n const studentObject = await context.model('Student').where('id').equal(student.id).silent().flatten().getItem();\n \n const academicYear = context.model('AcademicYear').convert(event.target.academicYear).getId();\n if (Number.isInteger(academicYear) === false) {\n throw new DataError('E_VALUE', 'Invalid academic year. Expected number.', null, 'AcademicYear', 'id');\n }\n\n const academicYearObject = await context.model('AcademicYear').where('id').equal(academicYear).getItem();\n if (academicYearObject === undefined){\n throw new DataError('E_VALUE', 'Invalid academic year.', null, 'AcademicYear', 'id');\n }\n\n if (event.target.academicPeriod != null){\n\n const academicPeriod = context.model('AcademicPeriod').convert(event.target.academicPeriod).getId();\n if (Number.isInteger(academicPeriod) === false) {\n throw new DataError('E_VALUE', 'Invalid academic period. Expected number.', null, 'AcademicPeriod', 'id');\n }\n \n const academicPeriodObject = await context.model('AcademicPeriod').where('id').equal(academicPeriod).getItem();\n if (academicPeriodObject === undefined){\n throw new DataError('E_VALUE', 'Invalid academic period.', null, 'AcademicPeriod', 'id');\n }\n \n }\n }\n })().then( () => {\n return callback();\n }).catch( err => {\n return callback(err);\n });\n}\n\n\n/**\n * @param {DataEventArgs} event\n * @param {Function} callback\n */\nexport function afterSave(event, callback) {\n (async () => {\n //\n let context = event.model.context;\n if (event.state === 1) {\n if (event.target.accommodationRoom && Object.keys(event.target.accommodationRoom).length != 0) {\n // get accommodation valid through date\n\n const room = await context.model('AccommodationRoom').where('id').equal(event.target.accommodationRoom.id).getItem();\n if (room === undefined) {\n throw new DataError('E_VALUE', 'Invalid accommodation room.', null, 'AccommodationRoom', 'id');\n }\n let newRoom = room;\n newRoom.currentOccupancy = room.currentOccupancy+1;\n //todo if i can increase occupancy\n await context.model('AccommodationRoom').silent().save(newRoom);\n }\n }\n\n\n })().then(() => {\n return callback();\n }).catch(err => {\n return callback(err);\n });\n}\n"],"mappings":";;;;AAIA,IAAAA,OAAA,GAAAC,OAAA,oBAA0C,CAJ1C;AACA;AACA;AACA,GAGO,SAASC,UAAUA,CAACC,KAAK,EAAEC,QAAQ,EAAE,CACxC,CA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AI,CAAChC,KAAK,CAACO,MAAM,CAACuB,iBAAiB,CAAC,CAACG,MAAM,IAAI,CAAC,EAAE;QAC3F;;QAEA,MAAMC,IAAI,GAAG,MAAM/B,OAAO,CAACC,KAAK,CAAC,mBAAmB,CAAC,CAACQ,KAAK,CAAC,IAAI,CAAC,CAACC,KAAK,CAACb,KAAK,CAACO,MAAM,CAACuB,iBAAiB,CAAChB,EAAE,CAAC,CAACG,OAAO,EAAE;QACpH,IAAIiB,IAAI,KAAKX,SAAS,EAAE;UACpB,MAAM,IAAIb,iBAAS,CAAC,SAAS,EAAE,6BAA6B,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,CAAC;QAClG;QACA,IAAIyB,OAAO,GAAGD,IAAI;QAClBC,OAAO,CAACC,gBAAgB,GAAGF,IAAI,CAACE,gBAAgB,GAAC,CAAC;QAClD;QACA,MAAMjC,OAAO,CAACC,KAAK,CAAC,mBAAmB,CAAC,CAACW,MAAM,EAAE,CAACsB,IAAI,CAACF,OAAO,CAAC;MACnE;IACJ;;;EAGJ,CAAC,GAAG,CAACT,IAAI,CAAC,MAAM;IACZ,OAAOzB,QAAQ,EAAE;EACrB,CAAC,CAAC,CAAC0B,KAAK,CAAC,CAAAC,GAAG,KAAI;IACZ,OAAO3B,QAAQ,CAAC2B,GAAG,CAAC;EACxB,CAAC,CAAC;AACN"}
1
+ {"version":3,"file":"StudentAccommodationCardSaveListener.js","names":["_common","require","beforeSave","event","callback","state","context","model","previous","student","convert","target","DataError","isActive","is","Object","prototype","hasOwnProperty","call","previousActionStatus","find","cardStatus","select","value","targetActionStatus","academicYear","getId","Number","isInteger","academicYearObject","where","equal","getItem","undefined","academicPeriod","academicPeriodObject","then","catch","err","afterSave","accommodationRoom","keys","length","room","id","newRoom","currentOccupancy","silent","save"],"sources":["../../src/listeners/StudentAccommodationCardSaveListener.js"],"sourcesContent":["/**\n * @param {DataEventArgs} event\n * @param {Function} callback\n */\nimport {DataError} from \"@themost/common\";\n\nexport function beforeSave(event, callback) {\n (async () => {\n\n // validate student state (on insert or update)\n if (event.state === 1 || event.state === 2) {\n let context = event.model.context;\n /**\n * @type {Student|DataObject|*}\n */\n const previous = event.previous;\n let student = context.model('Student').convert(event.target.student);\n if (!student){\n if (previous){\n student = context.model('Student').convert(previous.student);\n }else{\n throw new DataError('ERR_STATUS','Student cannot be found');\n }\n }\n const isActive = await student.is(':active');\n \n if (!isActive && event.state===1)\n {\n throw new DataError('ERR_STATUS',\n 'Invalid student status. Student Accommodation Card may be published upon an active student only.'+student\n , null,\n 'Student', 'studentStatus');\n }\n if (Object.prototype.hasOwnProperty.call(event.target, 'CardStatus')) {\n const previousActionStatus = await context.model('ActionStatusType').find(previous.cardStatus).select('alternateName').value();\n const targetActionStatus = await context.model('ActionStatusType').find(event.target.cardStatus).select('alternateName').value();\n if (!isActive && previousActionStatus !== targetActionStatus && targetActionStatus!=='CancelledActionStatus') {\n throw new DataError('ERR_STATUS',\n 'The student accommodation card cannot be activated for an inactive student' + student\n , null,\n 'Student', 'studentStatus');\n }\n }\n \n const academicYear = context.model('AcademicYear').convert(event.target.academicYear).getId();\n if (Number.isInteger(academicYear) === false) {\n throw new DataError('E_VALUE', 'Invalid academic year. Expected number.', null, 'AcademicYear', 'id');\n }\n\n const academicYearObject = await context.model('AcademicYear').where('id').equal(academicYear).getItem();\n if (academicYearObject === undefined){\n throw new DataError('E_VALUE', 'Invalid academic year.', null, 'AcademicYear', 'id');\n }\n\n if (event.target.academicPeriod != null){\n\n const academicPeriod = context.model('AcademicPeriod').convert(event.target.academicPeriod).getId();\n if (Number.isInteger(academicPeriod) === false) {\n throw new DataError('E_VALUE', 'Invalid academic period. Expected number.', null, 'AcademicPeriod', 'id');\n }\n \n const academicPeriodObject = await context.model('AcademicPeriod').where('id').equal(academicPeriod).getItem();\n if (academicPeriodObject === undefined){\n throw new DataError('E_VALUE', 'Invalid academic period.', null, 'AcademicPeriod', 'id');\n }\n \n }\n }\n })().then( () => {\n return callback();\n }).catch( err => {\n return callback(err);\n });\n}\n\n\n/**\n * @param {DataEventArgs} event\n * @param {Function} callback\n */\nexport function afterSave(event, callback) {\n (async () => {\n //\n let context = event.model.context;\n if (event.state === 1) {\n if (event.target.accommodationRoom && Object.keys(event.target.accommodationRoom).length != 0) {\n // get accommodation valid through date\n\n const room = await context.model('AccommodationRoom').where('id').equal(event.target.accommodationRoom.id).getItem();\n if (room === undefined) {\n throw new DataError('E_VALUE', 'Invalid accommodation room.', null, 'AccommodationRoom', 'id');\n }\n let newRoom = room;\n newRoom.currentOccupancy = room.currentOccupancy+1;\n //todo if i can increase occupancy\n await context.model('AccommodationRoom').silent().save(newRoom);\n }\n }\n\n\n })().then(() => {\n return callback();\n }).catch(err => {\n return callback(err);\n });\n}\n"],"mappings":";;;;AAIA,IAAAA,OAAA,GAAAC,OAAA,oBAA0C,CAJ1C;AACA;AACA;AACA,GAGO,SAASC,UAAUA,CAACC,KAAK,EAAEC,QAAQ,EAAE,CACxC,CAAC,YAAY;;IAET;IACA,IAAID,KAAK,CAACE,KAAK,KAAK,CAAC,IAAIF,KAAK,CAACE,KAAK,KAAK,CAAC,EAAE;MACxC,IAAIC,OAAO,GAAGH,KAAK,CAACI,KAAK,CAACD,OAAO;MACjC;AACZ;AACA;MACY,MAAME,QAAQ,GAAGL,KAAK,CAACK,QAAQ;MAC/B,IAAIC,OAAO,GAAGH,OAAO,CAACC,KAAK,CAAC,SAAS,CAAC,CAACG,OAAO,CAACP,KAAK,CAACQ,MAAM,CAACF,OAAO,CAAC;MACpE,IAAI,CAACA,OAAO,EAAC;QACT,IAAID,QAAQ,EAAC;UACTC,OAAO,GAAGH,OAAO,CAACC,KAAK,CAAC,SAAS,CAAC,CAACG,OAAO,CAACF,QAAQ,CAACC,OAAO,CAAC;QAChE,CAAC,MAAI;UACD,MAAM,IAAIG,iBAAS,CAAC,YAAY,EAAC,yBAAyB,CAAC;QAC/D;MACJ;MACA,MAAMC,QAAQ,GAAG,MAAMJ,OAAO,CAACK,EAAE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A,IAAIE,OAAO,GAAGH,KAAK,CAACI,KAAK,CAACD,OAAO;IACjC,IAAIH,KAAK,CAACE,KAAK,KAAK,CAAC,EAAE;MACnB,IAAIF,KAAK,CAACQ,MAAM,CAAC6B,iBAAiB,IAAIzB,MAAM,CAAC0B,IAAI,CAACtC,KAAK,CAACQ,MAAM,CAAC6B,iBAAiB,CAAC,CAACE,MAAM,IAAI,CAAC,EAAE;QAC3F;;QAEA,MAAMC,IAAI,GAAG,MAAMrC,OAAO,CAACC,KAAK,CAAC,mBAAmB,CAAC,CAACuB,KAAK,CAAC,IAAI,CAAC,CAACC,KAAK,CAAC5B,KAAK,CAACQ,MAAM,CAAC6B,iBAAiB,CAACI,EAAE,CAAC,CAACZ,OAAO,EAAE;QACpH,IAAIW,IAAI,KAAKV,SAAS,EAAE;UACpB,MAAM,IAAIrB,iBAAS,CAAC,SAAS,EAAE,6BAA6B,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,CAAC;QAClG;QACA,IAAIiC,OAAO,GAAGF,IAAI;QAClBE,OAAO,CAACC,gBAAgB,GAAGH,IAAI,CAACG,gBAAgB,GAAC,CAAC;QAClD;QACA,MAAMxC,OAAO,CAACC,KAAK,CAAC,mBAAmB,CAAC,CAACwC,MAAM,EAAE,CAACC,IAAI,CAACH,OAAO,CAAC;MACnE;IACJ;;;EAGJ,CAAC,GAAG,CAACT,IAAI,CAAC,MAAM;IACZ,OAAOhC,QAAQ,EAAE;EACrB,CAAC,CAAC,CAACiC,KAAK,CAAC,CAAAC,GAAG,KAAI;IACZ,OAAOlC,QAAQ,CAACkC,GAAG,CAAC;EACxB,CAAC,CAAC;AACN"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  var _data = require("@themost/data");
3
- var _common = require("@themost/common");var _dec, _dec2, _dec3, _class, _class2;function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object.keys(descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object.defineProperty(target, property, desc);desc = null;}return desc;}
3
+ var _common = require("@themost/common");
4
+ var _EnableAttachmentModel = _interopRequireDefault(require("./EnableAttachmentModel"));var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _class, _class2;function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object.keys(descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object.defineProperty(target, property, desc);desc = null;}return desc;}
4
5
 
5
6
  /**
6
7
  * @class
@@ -31,63 +32,185 @@ StudentAccommodationCard = (_dec = _data.EdmMapping.entityType('StudentAccommoda
31
32
 
32
33
 
33
34
  _data.EdmMapping.param('data', 'Object', false, true), _dec3 =
34
- _data.EdmMapping.action('cancel', 'StudentAccommodationCard'), _dec(_class = (_class2 = class StudentAccommodationCard extends _data.DataObject {/**
35
- * @constructor
36
- */constructor() {super();} /**
37
- * POST StudentAccommodationCards/:id/Cancel
38
- */async cancel(data) {if (!data.cancelReason) {
39
- throw new _common.DataError('E_CANCEL_REASON', 'Cancel Reason should be provided');
40
- }
41
-
42
- await this.context.executeInTransactionAsync(async () => {
43
- // find StudentAccommodationCard from id
44
- const StudentAccommodationCard = await this.context.model('StudentAccommodationCard').
45
- where('id').
46
- equal(this.getId()).
47
- select('id', 'active', 'action', 'student', 'academicPeriod', 'academicYear').
48
- flatten().
49
- getItem();
35
+ _data.EdmMapping.action('cancel', 'StudentAccommodationCard'), _dec4 =
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+ _data.EdmMapping.param('data', 'Object', false, true), _dec5 =
73
+ _data.EdmMapping.action('changeRoom', 'StudentAccommodationCard'), _dec6 =
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
50
97
 
51
- // validate existance and permission
52
- if (StudentAccommodationCard == null) {
53
- throw new _common.DataNotFoundError('The specified Student Accommodation Card cannot be found or is inaccessible');
54
- }
55
- // StudentAccommodationCard already cancelled throw error
56
- if (StudentAccommodationCard.active === false) {
57
- throw new _common.DataError('E_ACTIVE', 'The specified Student Accommodation Card is already cancelled');
58
- }
59
98
 
60
- //validate AccommodationRequestAction
61
- if (StudentAccommodationCard.action == null) {
62
- throw new _common.DataError('E_ACTION', 'The Student Accommodation Card is not linked to a Accommodation Request Action');
63
- }
64
99
 
65
- // cancel StudentAccommodationCard
66
- StudentAccommodationCard.cardStatus = { alternateName: "CancelledActionStatus" };
67
- StudentAccommodationCard.cancelReason = data.cancelReason;
68
- await this.context.model('StudentAccommodationCard').save(StudentAccommodationCard);
69
100
 
70
- const action = await this.context.model('AccommodationRequestAction').where('id').equal(StudentAccommodationCard.action).select('id', 'actionStatus/alternateName as requestStatus').getItem();
71
- //validate AccommodationRequestAction
72
- if (action == null) {
73
- throw new _common.DataError('E_ACTION', 'The specified AccommodationRequestAction cannot be found or is inaccessible');
74
- }
75
101
 
76
- if (action.requestStatus !== 'CompletedActionStatus') {
77
- throw new _common.DataError('E_ACTION', 'The specified AccommodationRequestAction is not in Completed state');
78
- }
79
102
 
80
- action.actionStatus = {
81
- alternateName: "ActiveActionStatus"
82
- };
83
103
 
84
- delete action.requestStatus;
85
- await this.context.model('AccommodationRequestAction').save(action);
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ _data.EdmMapping.param('data', 'Object', false, true), _dec7 =
134
+ _data.EdmMapping.action('addToRoom', 'StudentAccommodationCard'), _dec8 =
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+ _data.EdmMapping.param('data', 'Object', false, true), _dec9 =
164
+ _data.EdmMapping.action('revertToPending', 'StudentAccommodationCard'), _dec(_class = (_class2 = class StudentAccommodationCard extends _EnableAttachmentModel.default {/**
165
+ * @constructor
166
+ */constructor() {super();} /**
167
+ * POST StudentAccommodationCards/:id/Cancel
168
+ */async cancel(data) {_common.Args.notEmpty(data.cancelReason, 'Cancel Reason');if (!_common.LangUtils.isDate(data.dateCancelled)) {throw new _common.DataError('E_STATE', 'Cancel date can not be empty or invalid date');}await this.context.executeInTransactionAsync(async () => {var _currentStudentAccomm, _currentStudentAccomm2; // find StudentAccommodationCard from id
169
+ const currentStudentAccommodationCard = await this.context.model('StudentAccommodationCard').where('id').equal(this.getId()).select('id', 'serialNumber', 'action', 'student', 'cardStatus', 'academicYear', 'isActive', 'validThrough', 'accommodationRoom').expand('cardStatus').getItem();_common.Args.notNull(currentStudentAccommodationCard, 'The specified Student Accommodation Card'); // StudentAccommodationCard already cancelled throw error
170
+ if ((currentStudentAccommodationCard === null || currentStudentAccommodationCard === void 0 ? void 0 : (_currentStudentAccomm = currentStudentAccommodationCard.cardStatus) === null || _currentStudentAccomm === void 0 ? void 0 : _currentStudentAccomm.alternateName) === 'CompletedActionStatus') {throw new _common.DataError('E_ACTIVE', 'The specified Student Accommodation Card in not active');} // cancel StudentAccommodationCard
171
+ currentStudentAccommodationCard.cardStatus = { alternateName: 'CompletedActionStatus' };currentStudentAccommodationCard.cancelReason = data.cancelReason;currentStudentAccommodationCard.dateCancelled = data.dateCancelled;await this.context.model('StudentAccommodationCard').save(currentStudentAccommodationCard);const room = ((_currentStudentAccomm2 = currentStudentAccommodationCard.accommodationRoom) === null || _currentStudentAccomm2 === void 0 ? void 0 : _currentStudentAccomm2.id) || (currentStudentAccommodationCard === null || currentStudentAccommodationCard === void 0 ? void 0 : currentStudentAccommodationCard.accommodationRoom);_common.Args.notNull(room, 'Accommodation room can not be empty');_common.Args.notNumber(room, 'Accommodation room should be a number');await calculateOccupancy(this.context, room);}, (err) => {_common.TraceUtils.log(err);});}async changeRoom(data) {var _data$accommodationRo;const room = ((_data$accommodationRo = data.accommodationRoom) === null || _data$accommodationRo === void 0 ? void 0 : _data$accommodationRo.id) || (data === null || data === void 0 ? void 0 : data.accommodationRoom);_common.Args.notNull(room, 'Accommodation room can not be empty');_common.Args.notNumber(room, 'Accommodation room should be a number');if (!_common.LangUtils.isDate(data.validThrough)) {throw new _common.DataError('E_STATE', 'Valid through date can not be empty or it is not a valid date');}_common.Args.notEmpty(data.cancelReason, 'Cancel Reason cannot be empty');if (!_common.LangUtils.isDate(data.dateCancelled)) {throw new _common.DataError('E_STATE', 'Cancel date can not be empty or invalid date');}await this.context.executeInTransactionAsync(async () => {var _currentStudentAccomm3, _currentStudentAccomm4;const currentStudentAccommodationCard = await this.context.model('StudentAccommodationCard').where('id').equal(this.getId()).select('id', 'serialNumber', 'action', 'student', 'cardStatus', 'academicYear', 'isActive', 'validThrough', 'accommodationRoom').expand('cardStatus').getItem();_common.Args.notNull(currentStudentAccommodationCard, 'The specified Student Accommodation Card cannot be found or is inaccessible');if ((currentStudentAccommodationCard === null || currentStudentAccommodationCard === void 0 ? void 0 : (_currentStudentAccomm3 = currentStudentAccommodationCard.cardStatus) === null || _currentStudentAccomm3 === void 0 ? void 0 : _currentStudentAccomm3.alternateName) !== 'ActiveActionStatus') {throw new _common.DataError('E_STATE', 'The accommodation room cannot be changed for inactive accommodation card');}const newCard = { action: currentStudentAccommodationCard.action, student: currentStudentAccommodationCard.student, accommodationRoom: room, academicYear: currentStudentAccommodationCard.academicYear, validFrom: data.validThrough, validThrough: currentStudentAccommodationCard.validThrough, cardStatus: { alternateName: 'ActiveActionStatus' } };currentStudentAccommodationCard.cancelReason = data.cancelReason;currentStudentAccommodationCard.dateCancelled = data.dateCancelled;currentStudentAccommodationCard.validThrough = data.dateCancelled;delete currentStudentAccommodationCard.cardStatus;currentStudentAccommodationCard.cardStatus = { alternateName: 'CompletedActionStatus' };await this.context.model('StudentAccommodationCard').save(currentStudentAccommodationCard);const currentAccommodationRoom = ((_currentStudentAccomm4 = currentStudentAccommodationCard.accommodationRoom) === null || _currentStudentAccomm4 === void 0 ? void 0 : _currentStudentAccomm4.id) || (currentStudentAccommodationCard === null || currentStudentAccommodationCard === void 0 ? void 0 : currentStudentAccommodationCard.accommodationRoom);_common.Args.notNull(currentAccommodationRoom, 'The specified Student Accommodation Card does not contain any room');await calculateOccupancy(this.context, currentAccommodationRoom);await this.context.model('StudentAccommodationCards').save(newCard);await calculateOccupancy(this.context, room);}, (err) => {_common.TraceUtils.log(err);});}async addToRoom(data) {var _data$accommodationRo2;const room = ((_data$accommodationRo2 = data.accommodationRoom) === null || _data$accommodationRo2 === void 0 ? void 0 : _data$accommodationRo2.id) || (data === null || data === void 0 ? void 0 : data.accommodationRoom);_common.Args.notNull(room, 'Accommodation room can not be empty');_common.Args.notNumber(room, 'Accommodation room should be a number');if (!_common.LangUtils.isDate(data.validFrom)) {throw new _common.DataError('E_STATE', 'Valid through date can not be empty or it is not a valid date');}await this.context.executeInTransactionAsync(async () => {var _currentStudentAccomm5;const currentStudentAccommodationCard = await this.context.model('StudentAccommodationCard').where('id').equal(this.getId()).select('id', 'serialNumber', 'action', 'student', 'cardStatus', 'academicYear', 'isActive', 'validThrough').expand('cardStatus').getItem();_common.Args.notNull(currentStudentAccommodationCard, 'The specified Student Accommodation Card cannot be found or is inaccessible');if ((currentStudentAccommodationCard === null || currentStudentAccommodationCard === void 0 ? void 0 : (_currentStudentAccomm5 = currentStudentAccommodationCard.cardStatus) === null || _currentStudentAccomm5 === void 0 ? void 0 : _currentStudentAccomm5.alternateName) !== 'ActiveActionStatus') {throw new _common.DataError('E_STATE', 'Add to room action can only be applied when student accommodation card status is Active');}currentStudentAccommodationCard.accommodationRoom = room;currentStudentAccommodationCard.validFrom = data.validFrom;await this.context.model('StudentAccommodationCard').save(currentStudentAccommodationCard);await calculateOccupancy(this.context, room); // calculate occupancy after new room updated
172
+ }, (err) => {_common.TraceUtils.log(err);});}async revertToPending(data) {await this.context.executeInTransactionAsync(async () => {var _currentStudentAccomm6, _currentStudentAccomm7;const currentStudentAccommodationCard = await this.context.model('StudentAccommodationCard').where('id').equal(this.getId()).select('id', 'serialNumber', 'action', 'student', 'cardStatus', 'academicYear', 'isActive', 'validThrough', 'accommodationRoom').expand('cardStatus').
173
+ getItem();
174
+
175
+ _common.Args.notNull(currentStudentAccommodationCard, 'The specified Student Accommodation Card cannot be found or is inaccessible');
176
+ if ((currentStudentAccommodationCard === null || currentStudentAccommodationCard === void 0 ? void 0 : (_currentStudentAccomm6 = currentStudentAccommodationCard.cardStatus) === null || _currentStudentAccomm6 === void 0 ? void 0 : _currentStudentAccomm6.alternateName) !== 'ActiveActionStatus') {
177
+ throw new _common.DataError('E_STATE', 'Inactive accommodation card');
178
+ }
179
+
180
+ const accommodationRoom = ((_currentStudentAccomm7 = currentStudentAccommodationCard.accommodationRoom) === null || _currentStudentAccomm7 === void 0 ? void 0 : _currentStudentAccomm7.id) || (currentStudentAccommodationCard === null || currentStudentAccommodationCard === void 0 ? void 0 : currentStudentAccommodationCard.accommodationRoom);
181
+ currentStudentAccommodationCard.cardStatus = { alternateName: 'ActiveActionStatus' };
182
+ currentStudentAccommodationCard.accommodationRoom = null;
183
+ await this.context.model('StudentAccommodationCard').save(currentStudentAccommodationCard);
184
+ await calculateOccupancy(this.context, accommodationRoom);
86
185
  });
87
186
  }
88
187
 
89
188
 
90
- }, (_applyDecoratedDescriptor(_class2.prototype, "cancel", [_dec2, _dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "cancel"), _class2.prototype)), _class2)) || _class);
189
+ }, (_applyDecoratedDescriptor(_class2.prototype, "cancel", [_dec2, _dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "cancel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "changeRoom", [_dec4, _dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "changeRoom"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addToRoom", [_dec6, _dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "addToRoom"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "revertToPending", [_dec8, _dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "revertToPending"), _class2.prototype)), _class2)) || _class);
190
+ async function calculateOccupancy(context, accommodationRoom) {
191
+ if (accommodationRoom == null) {
192
+ return;
193
+ }
194
+ const currentOccupancy = await context.model('StudentAccommodationCard').
195
+ where('accommodationRoom').equal(accommodationRoom).
196
+ and('cardStatus/alternateName').equal('ActiveActionStatus').
197
+ and('accommodationRoom/outOfService').equal(0).
198
+ and('accommodationRoom/roomType/accessibleType').equal(1).
199
+ select('count(id) as total', 'accommodationRoom/occupancy as maxOccupancy').
200
+ groupBy('accommodationRoom/occupancy').
201
+ silent().
202
+ getItem();
203
+
204
+ const totalOccupancy = currentOccupancy && currentOccupancy.total || 0;
205
+ if (totalOccupancy && totalOccupancy > currentOccupancy.maxOccupancy) {
206
+ throw new _common.DataError('E_STATE', 'No room space for new resident');
207
+ }
208
+
209
+ await context.model('AccommodationRoom').save({
210
+ id: accommodationRoom,
211
+ currentOccupancy: totalOccupancy
212
+ });
213
+ }
91
214
 
92
215
  module.exports = StudentAccommodationCard;
93
216
  //# sourceMappingURL=StudentAccommodationCard.js.map