@universis/accommodation 1.0.0
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.
- package/.gitlab-ci.yml +23 -0
- package/LICENSE +163 -0
- package/README.md +3 -0
- package/dist/AccommodationSchemaLoader.js +35 -0
- package/dist/AccommodationSchemaLoader.js.map +1 -0
- package/dist/AccommodationService.js +68 -0
- package/dist/AccommodationService.js.map +1 -0
- package/dist/DepartmentReplacer.js +54 -0
- package/dist/DepartmentReplacer.js.map +1 -0
- package/dist/StudentReplacer.js +75 -0
- package/dist/StudentReplacer.js.map +1 -0
- package/dist/config/models/Accommodation.json +96 -0
- package/dist/config/models/AccommodationCardEffectiveStatusType.json +107 -0
- package/dist/config/models/AccommodationCardEffectiveStatusTypeLocale.json +85 -0
- package/dist/config/models/AccommodationChildFinancialAttribute.json +46 -0
- package/dist/config/models/AccommodationGuardianFinancialAttribute.json +46 -0
- package/dist/config/models/AccommodationInscriptionModeTag.json +100 -0
- package/dist/config/models/AccommodationRequestAction.json +500 -0
- package/dist/config/models/AccommodationRequestActionMessage.json +46 -0
- package/dist/config/models/AccommodationRequestActionReview.json +31 -0
- package/dist/config/models/AccommodationRequestAttachmentConfiguration.json +72 -0
- package/dist/config/models/AccommodationRequestCategory.json +50 -0
- package/dist/config/models/AccommodationRequestEffectiveStatusType.json +212 -0
- package/dist/config/models/AccommodationRequestEffectiveStatusTypeLocale.json +85 -0
- package/dist/config/models/AccommodationRequestEvent.json +117 -0
- package/dist/config/models/AccommodationRequestFinancialAttribute.json +53 -0
- package/dist/config/models/AccommodationRoom.json +151 -0
- package/dist/config/models/AccommodationSiblingFinancialAttribute.json +57 -0
- package/dist/config/models/CancelAccommodationCardAction.json +32 -0
- package/dist/config/models/GuardianType.json +78 -0
- package/dist/config/models/Review.json +50 -0
- package/dist/config/models/RoomType.json +320 -0
- package/dist/config/models/RoomTypeLocale.json +86 -0
- package/dist/config/models/StudentAccommodationCard.json +158 -0
- package/dist/config/models/TestAction.json +50 -0
- package/dist/config/scope.access.js +148 -0
- package/dist/config/scope.access.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/listeners/AddDefaultAttachmentConfiguration.js +44 -0
- package/dist/listeners/AddDefaultAttachmentConfiguration.js.map +1 -0
- package/dist/listeners/DefaultAttachmentConfigurations.json +277 -0
- package/dist/listeners/DefaultAttachmentTypes.json +523 -0
- package/dist/listeners/GenerateRequestNumberListener.js +87 -0
- package/dist/listeners/GenerateRequestNumberListener.js.map +1 -0
- package/dist/listeners/OnActionCompleteListener.js +96 -0
- package/dist/listeners/OnActionCompleteListener.js.map +1 -0
- package/dist/listeners/OnCancelAccommodationCardListener.js +87 -0
- package/dist/listeners/OnCancelAccommodationCardListener.js.map +1 -0
- package/dist/listeners/OnReactivateAccommodationCardListener.js +87 -0
- package/dist/listeners/OnReactivateAccommodationCardListener.js.map +1 -0
- package/dist/listeners/SendEmailAfterActionStatusChangeListener.js +98 -0
- package/dist/listeners/SendEmailAfterActionStatusChangeListener.js.map +1 -0
- package/dist/listeners/SendEmailAfterCardStatusChangeListener.js +139 -0
- package/dist/listeners/SendEmailAfterCardStatusChangeListener.js.map +1 -0
- package/dist/listeners/StudentAccommodationCardSaveListener.js +90 -0
- package/dist/listeners/StudentAccommodationCardSaveListener.js.map +1 -0
- package/dist/listeners/UpdateStudentAccommodationCardListener.js +70 -0
- package/dist/listeners/UpdateStudentAccommodationCardListener.js.map +1 -0
- package/dist/listeners/ValidateActionListener.js +348 -0
- package/dist/listeners/ValidateActionListener.js.map +1 -0
- package/dist/listeners/data-localization.js +209 -0
- package/dist/listeners/data-localization.js.map +1 -0
- package/dist/listeners/lookup-cache-listener.js +90 -0
- package/dist/listeners/lookup-cache-listener.js.map +1 -0
- package/dist/models/Accommodation.js +53 -0
- package/dist/models/Accommodation.js.map +1 -0
- package/dist/models/AccommodationRequestAction.js +214 -0
- package/dist/models/AccommodationRequestAction.js.map +1 -0
- package/dist/models/AccommodationRequestEvent.js +277 -0
- package/dist/models/AccommodationRequestEvent.js.map +1 -0
- package/dist/models/EnableAttachmentModel.js +210 -0
- package/dist/models/EnableAttachmentModel.js.map +1 -0
- package/dist/models/StudentAccommodationCard.js +93 -0
- package/dist/models/StudentAccommodationCard.js.map +1 -0
- package/dist/models/TestAction.d.ts +5 -0
- package/dist/models/TestAction.js +5 -0
- package/dist/models/TestAction.js.map +1 -0
- package/dist/templates/mail-after-dining-request-status-change/html.ejs +27 -0
- package/package.json +57 -0
- package/src/AccommodationSchemaLoader.js +35 -0
- package/src/AccommodationService.js +67 -0
- package/src/DepartmentReplacer.js +53 -0
- package/src/StudentReplacer.js +74 -0
- package/src/config/models/Accommodation.json +96 -0
- package/src/config/models/AccommodationCardEffectiveStatusType.json +107 -0
- package/src/config/models/AccommodationCardEffectiveStatusTypeLocale.json +85 -0
- package/src/config/models/AccommodationChildFinancialAttribute.json +46 -0
- package/src/config/models/AccommodationGuardianFinancialAttribute.json +46 -0
- package/src/config/models/AccommodationInscriptionModeTag.json +100 -0
- package/src/config/models/AccommodationRequestAction.json +500 -0
- package/src/config/models/AccommodationRequestActionMessage.json +46 -0
- package/src/config/models/AccommodationRequestActionReview.json +31 -0
- package/src/config/models/AccommodationRequestAttachmentConfiguration.json +72 -0
- package/src/config/models/AccommodationRequestCategory.json +50 -0
- package/src/config/models/AccommodationRequestEffectiveStatusType.json +212 -0
- package/src/config/models/AccommodationRequestEffectiveStatusTypeLocale.json +85 -0
- package/src/config/models/AccommodationRequestEvent.json +117 -0
- package/src/config/models/AccommodationRequestFinancialAttribute.json +53 -0
- package/src/config/models/AccommodationRoom.json +151 -0
- package/src/config/models/AccommodationSiblingFinancialAttribute.json +57 -0
- package/src/config/models/CancelAccommodationCardAction.json +32 -0
- package/src/config/models/GuardianType.json +78 -0
- package/src/config/models/Review.json +50 -0
- package/src/config/models/RoomType.json +320 -0
- package/src/config/models/RoomTypeLocale.json +86 -0
- package/src/config/models/StudentAccommodationCard.json +158 -0
- package/src/config/models/TestAction.json +50 -0
- package/src/config/scope.access.js +148 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/listeners/AddDefaultAttachmentConfiguration.js +43 -0
- package/src/listeners/DefaultAttachmentConfigurations.json +277 -0
- package/src/listeners/DefaultAttachmentTypes.json +523 -0
- package/src/listeners/GenerateRequestNumberListener.js +86 -0
- package/src/listeners/OnActionCompleteListener.js +95 -0
- package/src/listeners/OnCancelAccommodationCardListener.js +86 -0
- package/src/listeners/OnReactivateAccommodationCardListener.js +86 -0
- package/src/listeners/SendEmailAfterActionStatusChangeListener.js +97 -0
- package/src/listeners/SendEmailAfterCardStatusChangeListener.js +138 -0
- package/src/listeners/StudentAccommodationCardSaveListener.js +89 -0
- package/src/listeners/UpdateStudentAccommodationCardListener.js +69 -0
- package/src/listeners/ValidateActionListener.js +347 -0
- package/src/listeners/data-localization.js +214 -0
- package/src/listeners/lookup-cache-listener.js +89 -0
- package/src/models/Accommodation.js +52 -0
- package/src/models/AccommodationRequestAction.js +195 -0
- package/src/models/AccommodationRequestEvent.js +276 -0
- package/src/models/EnableAttachmentModel.js +209 -0
- package/src/models/StudentAccommodationCard.js +92 -0
- package/src/models/TestAction.d.ts +5 -0
- package/src/models/TestAction.js +10 -0
- package/src/templates/mail-after-dining-request-status-change/html.ejs +27 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.afterSave = afterSave;exports.beforeSave = beforeSave;exports.hasLocales = hasLocales;var _common = require("@themost/common");
|
|
2
|
+
var _elotConverter = require("@universis/elot-converter");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @name DataContext#locale
|
|
6
|
+
* @description Gets or sets the current context locale
|
|
7
|
+
* @type {string}
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if a data model has a localization enabled
|
|
11
|
+
* @param {DataModel} model
|
|
12
|
+
* @returns {DataField}
|
|
13
|
+
*/
|
|
14
|
+
function hasLocales(model) {
|
|
15
|
+
_common.Args.notNull(model, 'model');
|
|
16
|
+
const attribute = model.getAttribute('locales');
|
|
17
|
+
// if target model does not have a `locales` attribute
|
|
18
|
+
if (attribute == null) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
// if attribute belongs to another model (and it's being inherited by this model)
|
|
22
|
+
if (attribute.model !== model.name) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return attribute;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getElotAttributes(context) {
|
|
29
|
+
// do not require elotAttributes configuration
|
|
30
|
+
// make it completely optional
|
|
31
|
+
return context.getConfiguration().getSourceAt('settings/i18n/elotAttributes') || ['familyName', 'givenName', 'motherName', 'fatherName'];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getElotLocale() {
|
|
35
|
+
return {
|
|
36
|
+
requiresDefault: 'el',
|
|
37
|
+
isInLocale: 'en'
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @param {DataEventArgs} event
|
|
42
|
+
* @returns {Promise<void>}
|
|
43
|
+
*/
|
|
44
|
+
async function afterSaveAsync(event) {
|
|
45
|
+
const context = event.model.context;
|
|
46
|
+
const attribute = hasLocales(event.model);
|
|
47
|
+
if (attribute == null) {
|
|
48
|
+
// do nothing
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (Object.prototype.hasOwnProperty.call(event.target, 'locales') === false) {
|
|
52
|
+
// do nothing and exit because locales property is missing
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// get localized model
|
|
56
|
+
const childModel = context.model(attribute.type);
|
|
57
|
+
// throw error for invalid model
|
|
58
|
+
if (childModel == null) {
|
|
59
|
+
throw new Error('Invalid configuration. Localization model cannot be found or is not inaccessible yet');
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(event.target.locales) === false) {
|
|
62
|
+
throw new Error('Invalid property type. Property locales must be an array');
|
|
63
|
+
}
|
|
64
|
+
for (let i = 0; i < event.target.locales.length; i++) {
|
|
65
|
+
const itemLocale = event.target.locales[i];
|
|
66
|
+
if (childModel.sealed === false) {
|
|
67
|
+
// delete primary key if any
|
|
68
|
+
delete itemLocale[childModel.primaryKey];
|
|
69
|
+
}
|
|
70
|
+
if (itemLocale.object == null) {
|
|
71
|
+
// set object key
|
|
72
|
+
Object.defineProperty(itemLocale, 'object', {
|
|
73
|
+
configurable: true,
|
|
74
|
+
enumerable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: event.target[event.model.primaryKey]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (childModel.sealed === true) {
|
|
81
|
+
// if child model (locale model) is sealed add only other language (not default)
|
|
82
|
+
// get default application locale
|
|
83
|
+
let defaultLocale = context.getConfiguration().getSourceAt('settings/i18n/defaultLocale');
|
|
84
|
+
// throw error if default locale is not defined
|
|
85
|
+
if (defaultLocale == null) {
|
|
86
|
+
throw new Error('Invalid application configuration. The default locale is missing.');
|
|
87
|
+
}
|
|
88
|
+
event.target.locales = event.target.locales.filter((item) => {
|
|
89
|
+
return item.inLanguage !== defaultLocale;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// important note: get silent mode of parent model
|
|
93
|
+
const silentMode = event.model.isSilent();
|
|
94
|
+
// apply silent mode and save items
|
|
95
|
+
if (event.target.locales.length > 0) {
|
|
96
|
+
await childModel.silent(silentMode).save(event.target.locales);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @param {DataEventArgs} event
|
|
101
|
+
* @returns {Promise<void>}
|
|
102
|
+
*/
|
|
103
|
+
async function beforeSaveAsync(event) {
|
|
104
|
+
const context = event.model.context;
|
|
105
|
+
const attribute = hasLocales(event.model);
|
|
106
|
+
if (attribute == null) {
|
|
107
|
+
// do nothing
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// get localized model
|
|
111
|
+
const childModel = context.model(attribute.type);
|
|
112
|
+
// ensure locales property
|
|
113
|
+
event.target.locales = event.target.locales || [];
|
|
114
|
+
// get default application locale
|
|
115
|
+
let defaultLocale = context.getConfiguration().getSourceAt('settings/i18n/defaultLocale');
|
|
116
|
+
// throw error if default locale is not defined
|
|
117
|
+
if (defaultLocale == null) {
|
|
118
|
+
throw new Error('Invalid application configuration. The default locale is missing.');
|
|
119
|
+
}
|
|
120
|
+
let findLocale = event.target.locales.find((item) => {
|
|
121
|
+
return item.inLanguage === defaultLocale;
|
|
122
|
+
});
|
|
123
|
+
let add = false;
|
|
124
|
+
if (findLocale == null) {
|
|
125
|
+
add = true;
|
|
126
|
+
findLocale = {};
|
|
127
|
+
}
|
|
128
|
+
// enumerate properties and update object
|
|
129
|
+
childModel.attributes.forEach((attribute) => {
|
|
130
|
+
if (!attribute.primary && attribute.type !== event.model.name) {
|
|
131
|
+
if (Object.prototype.hasOwnProperty.call(event.target, attribute.name)) {
|
|
132
|
+
Object.defineProperty(findLocale, attribute.name, {
|
|
133
|
+
configurable: true,
|
|
134
|
+
enumerable: true,
|
|
135
|
+
writable: true,
|
|
136
|
+
value: event.target[attribute.name]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// set language
|
|
142
|
+
findLocale.inLanguage = defaultLocale;
|
|
143
|
+
if (add) {
|
|
144
|
+
event.target.locales.push(findLocale);
|
|
145
|
+
}
|
|
146
|
+
if (defaultLocale === getElotLocale().requiresDefault) {
|
|
147
|
+
// try to find locale that is in language of elot locale
|
|
148
|
+
let elotLocale = event.target.locales.find((locale) => locale.inLanguage === getElotLocale().isInLocale);
|
|
149
|
+
let addElotLocale = false;
|
|
150
|
+
if (!elotLocale) {
|
|
151
|
+
elotLocale = {};
|
|
152
|
+
addElotLocale = true;
|
|
153
|
+
}
|
|
154
|
+
// get elot attributes
|
|
155
|
+
const elotAttributes = getElotAttributes(context);
|
|
156
|
+
// if they are configured, validate them
|
|
157
|
+
if (!(Array.isArray(elotAttributes) && elotAttributes.length)) {
|
|
158
|
+
throw new Error('Invalid configuration. Elot attributes must be a (not-empty) array, e.g. ["familyName", "givenName"]');
|
|
159
|
+
}
|
|
160
|
+
// get previous state
|
|
161
|
+
// it can be undefined for various reasons (e.g. insert state, missing or misplaced previous-state-listener)
|
|
162
|
+
const previous = event.previous;
|
|
163
|
+
// enumerate elot attributes
|
|
164
|
+
for (const attribute of elotAttributes) {
|
|
165
|
+
// if target has the property
|
|
166
|
+
if (Object.prototype.hasOwnProperty.call(event.target, attribute)) {
|
|
167
|
+
// it's not null and has been changed
|
|
168
|
+
if (event.target[attribute] != null && event.target[attribute] != (previous && previous[attribute])) {
|
|
169
|
+
// convert and assign to elot locale
|
|
170
|
+
elotLocale[attribute] = _elotConverter.ElotConverter.convert(event.target[attribute]);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (addElotLocale) {
|
|
175
|
+
elotLocale.inLanguage = getElotLocale().isInLocale;
|
|
176
|
+
// and finally push the contructed locale
|
|
177
|
+
event.target.locales.push(elotLocale);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// noinspection JSUnusedGlobalSymbols
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
* @param {DataEventArgs} event
|
|
185
|
+
* @param {*} callback
|
|
186
|
+
* @returns {any}
|
|
187
|
+
*/
|
|
188
|
+
function beforeSave(event, callback) {
|
|
189
|
+
return beforeSaveAsync(event).then(() => {
|
|
190
|
+
return callback();
|
|
191
|
+
}).catch((err) => {
|
|
192
|
+
return callback(err);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// noinspection JSUnusedGlobalSymbols
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* @param {DataEventArgs} event
|
|
199
|
+
* @param {*} callback
|
|
200
|
+
* @returns {any}
|
|
201
|
+
*/
|
|
202
|
+
function afterSave(event, callback) {
|
|
203
|
+
return afterSaveAsync(event).then(() => {
|
|
204
|
+
return callback();
|
|
205
|
+
}).catch((err) => {
|
|
206
|
+
return callback(err);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=data-localization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-localization.js","names":["_common","require","_elotConverter","hasLocales","model","Args","notNull","attribute","getAttribute","name","getElotAttributes","context","getConfiguration","getSourceAt","getElotLocale","requiresDefault","isInLocale","afterSaveAsync","event","Object","prototype","hasOwnProperty","call","target","childModel","type","Error","Array","isArray","locales","i","length","itemLocale","sealed","primaryKey","object","defineProperty","configurable","enumerable","writable","value","defaultLocale","filter","item","inLanguage","silentMode","isSilent","silent","save","beforeSaveAsync","findLocale","find","add","attributes","forEach","primary","push","elotLocale","locale","addElotLocale","elotAttributes","previous","ElotConverter","convert","beforeSave","callback","then","catch","err","afterSave"],"sources":["../../src/listeners/data-localization.js"],"sourcesContent":["import {Args} from '@themost/common';\nimport {ElotConverter} from '@universis/elot-converter';\n\n/**\n * @name DataContext#locale\n * @description Gets or sets the current context locale\n * @type {string}\n */\n/**\n * Returns true if a data model has a localization enabled\n * @param {DataModel} model\n * @returns {DataField}\n */\nfunction hasLocales(model) {\n Args.notNull(model, 'model');\n const attribute = model.getAttribute('locales');\n // if target model does not have a `locales` attribute\n if (attribute == null) {\n return null;\n }\n // if attribute belongs to another model (and it's being inherited by this model)\n if (attribute.model !== model.name) {\n return null;\n }\n return attribute;\n}\n\nfunction getElotAttributes(context) {\n // do not require elotAttributes configuration\n // make it completely optional\n return context.getConfiguration().getSourceAt('settings/i18n/elotAttributes') || ['familyName', 'givenName', 'motherName', 'fatherName'];\n}\n\nfunction getElotLocale() {\n return {\n requiresDefault: 'el',\n isInLocale: 'en'\n }\n}\n/**\n * @param {DataEventArgs} event\n * @returns {Promise<void>}\n */\nasync function afterSaveAsync(event) {\n const context = event.model.context;\n const attribute = hasLocales(event.model);\n if (attribute == null) {\n // do nothing\n return;\n }\n if (Object.prototype.hasOwnProperty.call(event.target, 'locales') === false) {\n // do nothing and exit because locales property is missing\n return;\n }\n // get localized model\n const childModel = context.model(attribute.type);\n // throw error for invalid model\n if (childModel == null) {\n throw new Error('Invalid configuration. Localization model cannot be found or is not inaccessible yet');\n }\n if (Array.isArray(event.target.locales) === false) {\n throw new Error('Invalid property type. Property locales must be an array');\n }\n for (let i = 0; i < event.target.locales.length; i++) {\n const itemLocale = event.target.locales[i];\n if (childModel.sealed === false) {\n // delete primary key if any\n delete itemLocale[childModel.primaryKey];\n }\n if (itemLocale.object == null) {\n // set object key\n Object.defineProperty(itemLocale, 'object', {\n configurable: true,\n enumerable: true,\n writable: true,\n value: event.target[event.model.primaryKey]\n });\n }\n }\n if (childModel.sealed === true) {\n // if child model (locale model) is sealed add only other language (not default)\n // get default application locale\n let defaultLocale = context.getConfiguration().getSourceAt('settings/i18n/defaultLocale');\n // throw error if default locale is not defined\n if (defaultLocale == null) {\n throw new Error('Invalid application configuration. The default locale is missing.');\n }\n event.target.locales = event.target.locales.filter((item) => {\n return item.inLanguage !== defaultLocale;\n });\n }\n // important note: get silent mode of parent model\n const silentMode = event.model.isSilent();\n // apply silent mode and save items\n if (event.target.locales.length > 0) {\n await childModel.silent(silentMode).save(event.target.locales);\n }\n}\n/**\n * @param {DataEventArgs} event\n * @returns {Promise<void>}\n */\nasync function beforeSaveAsync(event) {\n const context = event.model.context;\n const attribute = hasLocales(event.model);\n if (attribute == null) {\n // do nothing\n return;\n }\n // get localized model\n const childModel = context.model(attribute.type);\n // ensure locales property\n event.target.locales = event.target.locales || [];\n // get default application locale\n let defaultLocale = context.getConfiguration().getSourceAt('settings/i18n/defaultLocale');\n // throw error if default locale is not defined\n if (defaultLocale == null) {\n throw new Error('Invalid application configuration. The default locale is missing.');\n }\n let findLocale = event.target.locales.find((item) => {\n return item.inLanguage === defaultLocale;\n });\n let add = false;\n if (findLocale == null) {\n add = true;\n findLocale = {};\n }\n // enumerate properties and update object\n childModel.attributes.forEach((attribute) => {\n if (!attribute.primary && attribute.type !== event.model.name) {\n if (Object.prototype.hasOwnProperty.call(event.target, attribute.name)) {\n Object.defineProperty(findLocale, attribute.name, {\n configurable: true,\n enumerable: true,\n writable: true,\n value: event.target[attribute.name]\n });\n }\n }\n });\n // set language\n findLocale.inLanguage = defaultLocale;\n if (add) {\n event.target.locales.push(findLocale);\n }\n if (defaultLocale === getElotLocale().requiresDefault) {\n // try to find locale that is in language of elot locale\n let elotLocale = event.target.locales.find(locale => locale.inLanguage === getElotLocale().isInLocale);\n let addElotLocale = false;\n if (!elotLocale) {\n elotLocale = {};\n addElotLocale = true;\n }\n // get elot attributes\n const elotAttributes = getElotAttributes(context);\n // if they are configured, validate them\n if (!(Array.isArray(elotAttributes) && elotAttributes.length)) {\n throw new Error('Invalid configuration. Elot attributes must be a (not-empty) array, e.g. [\"familyName\", \"givenName\"]');\n }\n // get previous state\n // it can be undefined for various reasons (e.g. insert state, missing or misplaced previous-state-listener)\n const previous = event.previous;\n // enumerate elot attributes\n for (const attribute of elotAttributes) {\n // if target has the property\n if (Object.prototype.hasOwnProperty.call(event.target, attribute)) {\n // it's not null and has been changed\n if (event.target[attribute] != null && event.target[attribute] != (previous && previous[attribute])) {\n // convert and assign to elot locale\n elotLocale[attribute] = ElotConverter.convert(event.target[attribute]);\n }\n }\n }\n if (addElotLocale) {\n elotLocale.inLanguage = getElotLocale().isInLocale;\n // and finally push the contructed locale\n event.target.locales.push(elotLocale);\n }\n }\n}\n// noinspection JSUnusedGlobalSymbols\n/**\n *\n * @param {DataEventArgs} event\n * @param {*} callback\n * @returns {any}\n */\nfunction beforeSave(event, callback) {\n return beforeSaveAsync(event).then(() => {\n return callback();\n }).catch((err) => {\n return callback(err);\n });\n}\n// noinspection JSUnusedGlobalSymbols\n/**\n *\n * @param {DataEventArgs} event\n * @param {*} callback\n * @returns {any}\n */\nfunction afterSave(event, callback) {\n return afterSaveAsync(event).then(() => {\n return callback();\n }).catch((err) => {\n return callback(err);\n });\n}\n\nexport {\n hasLocales,\n beforeSave,\n afterSave\n}\n"],"mappings":"yKAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,UAAUA,CAACC,KAAK,EAAE;EACvBC,YAAI,CAACC,OAAO,CAACF,KAAK,EAAE,OAAO,CAAC;EAC5B,MAAMG,SAAS,GAAGH,KAAK,CAACI,YAAY,CAAC,SAAS,CAAC;EAC/C;EACA,IAAID,SAAS,IAAI,IAAI,EAAE;IACnB,OAAO,IAAI;EACf;EACA;EACA,IAAIA,SAAS,CAACH,KAAK,KAAKA,KAAK,CAACK,IAAI,EAAE;IAChC,OAAO,IAAI;EACf;EACA,OAAOF,SAAS;AACpB;;AAEA,SAASG,iBAAiBA,CAACC,OAAO,EAAE;EAChC;EACA;EACA,OAAOA,OAAO,CAACC,gBAAgB,EAAE,CAACC,WAAW,CAAC,8BAA8B,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC;AAC5I;;AAEA,SAASC,aAAaA,CAAA,EAAG;EACrB,OAAO;IACHC,eAAe,EAAE,IAAI;IACrBC,UAAU,EAAE;EAChB,CAAC;AACL;AACA;AACA;AACA;AACA;AACA,eAAeC,cAAcA,CAACC,KAAK,EAAE;EACjC,MAAMP,OAAO,GAAGO,KAAK,CAACd,KAAK,CAACO,OAAO;EACnC,MAAMJ,SAAS,GAAGJ,UAAU,CAACe,KAAK,CAACd,KAAK,CAAC;EACzC,IAAIG,SAAS,IAAI,IAAI,EAAE;IACnB;IACA;EACJ;EACA,IAAIY,MAAM,CAACC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,KAAK,CAACK,MAAM,EAAE,SAAS,CAAC,KAAK,KAAK,EAAE;IACzE;IACA;EACJ;EACA;EACA,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ACrB,CAAC,CAAC,CAACE,KAAK,CAAC,CAACC,GAAG,KAAK;IACd,OAAOH,QAAQ,CAACG,GAAG,CAAC;EACxB,CAAC,CAAC;AACN"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.afterExecute = afterExecute;exports.afterRemove = afterRemove;exports.afterSave = afterSave;exports.beforeExecute = beforeExecute;var _common = require("@themost/common");
|
|
2
|
+
var _data = require("@themost/data");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {DataEventArgs} event
|
|
6
|
+
* @param {Function} callback
|
|
7
|
+
*/
|
|
8
|
+
function beforeExecute(event, callback) {
|
|
9
|
+
try {
|
|
10
|
+
const context = event.model.context;
|
|
11
|
+
if (event.query) {
|
|
12
|
+
if (event.query.$select) {
|
|
13
|
+
//create hash
|
|
14
|
+
const hash = event.emitter ? event.emitter.toMD5() : _common.TextUtils.toMD5(event.query);
|
|
15
|
+
const key = '/' + event.model.name + '/?query=' + hash + '&lang=' + event.model.context.locale;
|
|
16
|
+
_common.TraceUtils.debug('Getting data from cache [' + key + ']');
|
|
17
|
+
return context.getConfiguration().getStrategy(_data.DataCacheStrategy).get(key).then((result) => {
|
|
18
|
+
if (typeof result !== 'undefined') {
|
|
19
|
+
//delete expandables
|
|
20
|
+
if (event.emitter) {
|
|
21
|
+
delete event.emitter.$expand;
|
|
22
|
+
}
|
|
23
|
+
event.cached = true;
|
|
24
|
+
event.result = result;
|
|
25
|
+
return callback();
|
|
26
|
+
} else
|
|
27
|
+
{
|
|
28
|
+
return callback();
|
|
29
|
+
}
|
|
30
|
+
}).catch((err) => {
|
|
31
|
+
return callback(err);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
callback();
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
callback(e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function afterExecute(event, callback) {
|
|
43
|
+
try {
|
|
44
|
+
const context = event.model.context;
|
|
45
|
+
if (event.query) {
|
|
46
|
+
if (event.query.$select) {
|
|
47
|
+
if (typeof event.result !== 'undefined' && !event.cached) {
|
|
48
|
+
//create hash
|
|
49
|
+
const hash = event.emitter ? event.emitter.toMD5() : _common.TextUtils.toMD5(event.query);
|
|
50
|
+
const key = '/' + event.model.name + '/?query=' + hash + '&lang=' + event.model.context.locale;
|
|
51
|
+
_common.TraceUtils.debug('Setting data to cache [' + key + ']');
|
|
52
|
+
context.getConfiguration().getStrategy(_data.DataCacheStrategy).add(key, event.result);
|
|
53
|
+
return callback();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
callback();
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
callback(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function cleanupCache(event, callback) {
|
|
65
|
+
const { name, caching, context } = event.model;
|
|
66
|
+
if (caching === 'none') {
|
|
67
|
+
return callback();
|
|
68
|
+
}
|
|
69
|
+
const service = context.getConfiguration().getStrategy(_data.DataCacheStrategy);
|
|
70
|
+
if (service) {
|
|
71
|
+
return service.remove(`/${name}/*`).then(() => {
|
|
72
|
+
return callback();
|
|
73
|
+
}).catch((err) => {
|
|
74
|
+
_common.TraceUtils.warn('An error occurred while cleaning up cache items');
|
|
75
|
+
_common.TraceUtils.warn(err);
|
|
76
|
+
return callback();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return callback();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
function afterSave(event, callback) {
|
|
84
|
+
return cleanupCache(event, callback);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function afterRemove(event, callback) {
|
|
88
|
+
return cleanupCache(event, callback);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=lookup-cache-listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup-cache-listener.js","names":["_common","require","_data","beforeExecute","event","callback","context","model","query","$select","hash","emitter","toMD5","TextUtils","key","name","locale","TraceUtils","debug","getConfiguration","getStrategy","DataCacheStrategy","get","then","result","$expand","cached","catch","err","e","afterExecute","add","cleanupCache","caching","service","remove","warn","afterSave","afterRemove"],"sources":["../../src/listeners/lookup-cache-listener.js"],"sourcesContent":["import {TextUtils, TraceUtils} from '@themost/common';\nimport {DataCacheStrategy} from \"@themost/data\";\n\n/**\n * @param {DataEventArgs} event\n * @param {Function} callback\n */\nexport function beforeExecute(event, callback) {\n try {\n const context = event.model.context;\n if (event.query) {\n if (event.query.$select) {\n //create hash\n const hash = event.emitter? event.emitter.toMD5() : TextUtils.toMD5(event.query);\n const key = '/' + event.model.name + '/?query=' + hash + '&lang=' + event.model.context.locale;\n TraceUtils.debug('Getting data from cache [' + key + ']');\n return context.getConfiguration().getStrategy(DataCacheStrategy).get(key).then((result) => {\n if (typeof result !== 'undefined') {\n //delete expandables\n if (event.emitter) {\n delete event.emitter.$expand;\n }\n event.cached = true;\n event.result = result;\n return callback();\n }\n else {\n return callback();\n }\n }).catch((err)=> {\n return callback(err);\n });\n }\n }\n callback();\n }\n catch (e) {\n callback(e)\n }\n}\n\nexport function afterExecute(event, callback) {\n try {\n const context = event.model.context;\n if (event.query) {\n if (event.query.$select) {\n if (typeof event.result !== 'undefined' && !event.cached) {\n //create hash\n const hash = event.emitter? event.emitter.toMD5() : TextUtils.toMD5(event.query);\n const key = '/' + event.model.name + '/?query=' + hash + '&lang=' + event.model.context.locale;\n TraceUtils.debug('Setting data to cache [' + key + ']');\n context.getConfiguration().getStrategy(DataCacheStrategy).add(key, event.result);\n return callback();\n }\n }\n }\n callback();\n }\n catch (e) {\n callback(e)\n }\n}\n\nfunction cleanupCache(event, callback) {\n const { name, caching, context } = event.model;\n if (caching === 'none') {\n return callback();\n }\n const service = context.getConfiguration().getStrategy(DataCacheStrategy);\n if (service) {\n return service.remove(`/${name}/*`).then(() => {\n return callback();\n }).catch((err) => {\n TraceUtils.warn('An error occurred while cleaning up cache items');\n TraceUtils.warn(err);\n return callback();\n }); \n }\n return callback();\n}\n\n\nexport function afterSave(event, callback) {\n return cleanupCache(event, callback);\n}\n\nexport function afterRemove(event, callback) {\n return cleanupCache(event, callback);\n}\n"],"mappings":"qNAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;;AAEA;AACA;AACA;AACA;AACO,SAASE,aAAaA,CAACC,KAAK,EAAEC,QAAQ,EAAE;EAC3C,IAAI;IACA,MAAMC,OAAO,GAAGF,KAAK,CAACG,KAAK,CAACD,OAAO;IACnC,IAAIF,KAAK,CAACI,KAAK,EAAE;MACb,IAAIJ,KAAK,CAACI,KAAK,CAACC,OAAO,EAAE;QACrB;QACA,MAAMC,IAAI,GAAGN,KAAK,CAACO,OAAO,GAAEP,KAAK,CAACO,OAAO,CAACC,KAAK,EAAE,GAAGC,iBAAS,CAACD,KAAK,CAACR,KAAK,CAACI,KAAK,CAAC;QAChF,MAAMM,GAAG,GAAG,GAAG,GAAGV,KAAK,CAACG,KAAK,CAACQ,IAAI,GAAG,UAAU,GAAGL,IAAI,GAAG,QAAQ,GAAGN,KAAK,CAACG,KAAK,CAACD,OAAO,CAACU,MAAM;QAC9FC,kBAAU,CAACC,KAAK,CAAC,2BAA2B,GAAGJ,GAAG,GAAG,GAAG,CAAC;QACzD,OAAOR,OAAO,CAACa,gBAAgB,EAAE,CAACC,WAAW,CAACC,uBAAiB,CAAC,CAACC,GAAG,CAACR,GAAG,CAAC,CAACS,IAAI,CAAC,CAACC,MAAM,KAAK;UACvF,IAAI,OAAOA,MAAM,KAAK,WAAW,EAAE;YAC/B;YACA,IAAIpB,KAAK,CAACO,OAAO,EAAE;cACf,OAAOP,KAAK,CAACO,OAAO,CAACc,OAAO;YAChC;YACArB,KAAK,CAACsB,MAAM,GAAG,IAAI;YACnBtB,KAAK,CAACoB,MAAM,GAAGA,MAAM;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f;AACJ;;AAEA,SAASG,YAAYA,CAAC5B,KAAK,EAAEC,QAAQ,EAAE;EACnC,MAAM,EAAEU,IAAI,EAAEkB,OAAO,EAAE3B,OAAO,CAAC,CAAC,GAAGF,KAAK,CAACG,KAAK;EAC9C,IAAI0B,OAAO,KAAK,MAAM,EAAE;IACpB,OAAO5B,QAAQ,EAAE;EACrB;EACA,MAAM6B,OAAO,GAAG5B,OAAO,CAACa,gBAAgB,EAAE,CAACC,WAAW,CAACC,uBAAiB,CAAC;EACzE,IAAIa,OAAO,EAAE;IACT,OAAOA,OAAO,CAACC,MAAM,CAAE,IAAGpB,IAAK,IAAG,CAAC,CAACQ,IAAI,CAAC,MAAM;MAC3C,OAAOlB,QAAQ,EAAE;IACrB,CAAC,CAAC,CAACsB,KAAK,CAAC,CAACC,GAAG,KAAK;MACdX,kBAAU,CAACmB,IAAI,CAAC,iDAAiD,CAAC;MAClEnB,kBAAU,CAACmB,IAAI,CAACR,GAAG,CAAC;MACpB,OAAOvB,QAAQ,EAAE;IACrB,CAAC,CAAC;EACN;EACA,OAAOA,QAAQ,EAAE;AACrB;;;AAGO,SAASgC,SAASA,CAACjC,KAAK,EAAEC,QAAQ,EAAE;EACvC,OAAO2B,YAAY,CAAC5B,KAAK,EAAEC,QAAQ,CAAC;AACxC;;AAEO,SAASiC,WAAWA,CAAClC,KAAK,EAAEC,QAAQ,EAAE;EACzC,OAAO2B,YAAY,CAAC5B,KAAK,EAAEC,QAAQ,CAAC;AACxC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _common = require("@themost/common");
|
|
3
|
+
var _data = require("@themost/data");var _dec, _dec2, _dec3, _class, _class2; /* eslint-disable no-unused-vars */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;}let
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
AccommodationRequestEvent = (_dec = _data.EdmMapping.entityType('Accommodation'), _dec2 =
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
_data.EdmMapping.param('data', 'Object', false, true), _dec3 =
|
|
21
|
+
_data.EdmMapping.action('remove', 'Accommodation'), _dec(_class = (_class2 = class AccommodationRequestEvent extends _data.DataObject {/**
|
|
22
|
+
* @constructor
|
|
23
|
+
*/constructor() {super();} /**
|
|
24
|
+
* POST AccommodationRequestEvents/:id/Remove
|
|
25
|
+
*/ //remove accommodation request event
|
|
26
|
+
async remove(data) {/**
|
|
27
|
+
* @type {import('@themost/data').DataModel}
|
|
28
|
+
*/const model = this.getModel();
|
|
29
|
+
const item = await model.where('id').
|
|
30
|
+
equal(this.getId()).
|
|
31
|
+
getItem();
|
|
32
|
+
const translateService = this.context.application.getStrategy(function TranslateService() {});
|
|
33
|
+
|
|
34
|
+
if (item == null) {
|
|
35
|
+
throw new _common.DataError('E_ACCOMMODATION', translateService.translate('The specified Accommodation cannot be found or is inaccessible.'));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const hasRooms = await this.context.model('AccommodationRooms').
|
|
39
|
+
where('containedInPlace').equal(item.id).count();
|
|
40
|
+
|
|
41
|
+
if (hasRooms) {
|
|
42
|
+
throw new _common.DataError('E_ACCOMMODATION_ROOM', translateService.translate('Cannot remove accommodation. Accommodation is related to rooms.'), null, 'Accommodation');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return model.silent().remove(item);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
}, (_applyDecoratedDescriptor(_class2.prototype, "remove", [_dec2, _dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "remove"), _class2.prototype)), _class2)) || _class);
|
|
51
|
+
|
|
52
|
+
module.exports = AccommodationRequestEvent;
|
|
53
|
+
//# sourceMappingURL=Accommodation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Accommodation.js","names":["_common","require","_data","_dec","_dec2","_dec3","_class","_class2","_applyDecoratedDescriptor","target","property","decorators","descriptor","context","desc","Object","keys","forEach","key","enumerable","configurable","initializer","writable","slice","reverse","reduce","decorator","value","call","undefined","defineProperty","AccommodationRequestEvent","EdmMapping","entityType","param","action","DataObject","constructor","remove","data","model","getModel","item","where","equal","getId","getItem","translateService","application","getStrategy","TranslateService","DataError","translate","hasRooms","id","count","silent","prototype","getOwnPropertyDescriptor","module","exports"],"sources":["../../src/models/Accommodation.js"],"sourcesContent":["/* eslint-disable no-unused-vars */\nimport { DataError } from \"@themost/common\";\nimport { DataObject, EdmMapping } from \"@themost/data\";\n\n\n@EdmMapping.entityType('Accommodation')\nclass AccommodationRequestEvent extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n /**\n * POST AccommodationRequestEvents/:id/Remove\n */\n\n //remove accommodation request event\n @EdmMapping.param('data', 'Object', false, true)\n @EdmMapping.action('remove', 'Accommodation')\n async remove(data) {\n /**\n * @type {import('@themost/data').DataModel}\n */\n\n const model = this.getModel();\n\n const item = await model.where('id')\n .equal(this.getId())\n .getItem();\n const translateService = this.context.application.getStrategy(function TranslateService() { });\n\n if (item == null) {\n throw new DataError('E_ACCOMMODATION', translateService.translate('The specified Accommodation cannot be found or is inaccessible.'));\n }\n\n const hasRooms = await this.context.model('AccommodationRooms')\n .where('containedInPlace').equal(item.id).count();\n\n if (hasRooms) {\n throw new DataError('E_ACCOMMODATION_ROOM', translateService.translate('Cannot remove accommodation. Accommodation is related to rooms.'), null, 'Accommodation');\n }\n\n return model.silent().remove(item);\n }\n\n\n \n}\n\nmodule.exports = AccommodationRequestEvent;\n"],"mappings":";AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA,kBAAuD,IAAAE,IAAA,EAAAC,KAAA,EAAAC,KAAA,EAAAC,MAAA,EAAAC,OAAA,EAFvD,4CAAAC,0BAAAC,MAAA,EAAAC,QAAA,EAAAC,UAAA,EAAAC,UAAA,EAAAC,OAAA,OAAAC,IAAA,MAAAC,MAAA,CAAAC,IAAA,CAAAJ,UAAA,EAAAK,OAAA,WAAAC,GAAA,GAAAJ,IAAA,CAAAI,GAAA,IAAAN,UAAA,CAAAM,GAAA,KAAAJ,IAAA,CAAAK,UAAA,KAAAL,IAAA,CAAAK,UAAA,CAAAL,IAAA,CAAAM,YAAA,KAAAN,IAAA,CAAAM,YAAA,gBAAAN,IAAA,IAAAA,IAAA,CAAAO,WAAA,GAAAP,IAAA,CAAAQ,QAAA,SAAAR,IAAA,GAAAH,UAAA,CAAAY,KAAA,GAAAC,OAAA,GAAAC,MAAA,WAAAX,IAAA,EAAAY,SAAA,UAAAA,SAAA,CAAAjB,MAAA,EAAAC,QAAA,EAAAI,IAAA,KAAAA,IAAA,IAAAA,IAAA,MAAAD,OAAA,IAAAC,IAAA,CAAAO,WAAA,cAAAP,IAAA,CAAAa,KAAA,GAAAb,IAAA,CAAAO,WAAA,GAAAP,IAAA,CAAAO,WAAA,CAAAO,IAAA,CAAAf,OAAA,WAAAC,IAAA,CAAAO,WAAA,GAAAQ,SAAA,MAAAf,IAAA,CAAAO,WAAA,cAAAN,MAAA,CAAAe,cAAA,CAAArB,MAAA,EAAAC,QAAA,EAAAI,IAAA,EAAAA,IAAA,gBAAAA,IAAA;;;;AAMMiB,yBAAyB,IAAA5B,IAAA,GAD9B6B,gBAAU,CAACC,UAAU,CAAC,e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OZ,KAAK,CAACgB,MAAM,EAAE,CAAClB,MAAM,CAACI,IAAI,CAAC;EACtC;;;;AAIJ,CAAC,GAAAlC,yBAAA,CAAAD,OAAA,CAAAkD,SAAA,aAAArD,KAAA,EAAAC,KAAA,GAAAU,MAAA,CAAA2C,wBAAA,CAAAnD,OAAA,CAAAkD,SAAA,aAAAlD,OAAA,CAAAkD,SAAA,IAAAlD,OAAA,MAAAD,MAAA;;AAEDqD,MAAM,CAACC,OAAO,GAAG7B,yBAAyB"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";var _common = require("@themost/common");
|
|
2
|
+
var _data = require("@themost/data");
|
|
3
|
+
var _EnableAttachmentModel = _interopRequireDefault(require("./EnableAttachmentModel"));var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _class;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;}let
|
|
4
|
+
|
|
5
|
+
AccommodationRequestAction = (_dec =
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
_data.EdmMapping.param('extraAttributes', 'Object', true, true), _dec2 =
|
|
15
|
+
_data.EdmMapping.param('file', _data.EdmType.EdmStream, false), _dec3 =
|
|
16
|
+
_data.EdmMapping.action('AddAttachment', 'Attachment'), _dec4 =
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
_data.EdmMapping.param('attachment', 'Attachment', true, true), _dec5 =
|
|
28
|
+
_data.EdmMapping.action('RemoveAttachment', 'Attachment'), _dec6 =
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
_data.EdmMapping.param('attachment', 'Attachment', true, true), _dec7 =
|
|
38
|
+
_data.EdmMapping.action('RejectAttachment', 'Attachment'), _dec8 =
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
_data.EdmMapping.param('attachment', 'Attachment', true, true), _dec9 =
|
|
48
|
+
_data.EdmMapping.action('RevertAttachment', 'Attachment'), _dec10 =
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
_data.EdmMapping.param('item', 'AccommodationRequestActionMessage', true, true), _dec11 =
|
|
58
|
+
_data.EdmMapping.action('messages', 'AccommodationRequestActionMessage'), _dec12 =
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
_data.EdmMapping.func('review', 'AccommodationRequestActionReview'), _dec13 =
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
_data.EdmMapping.param('item', 'AccommodationRequestActionReview', true, true), _dec14 =
|
|
79
|
+
_data.EdmMapping.action('review', 'AccommodationRequestActionReview'), _dec15 =
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
_data.EdmMapping.param('message', 'Object', true, true), _dec16 =
|
|
111
|
+
_data.EdmMapping.param('attachment', _data.EdmType.EdmStream, true), _dec17 =
|
|
112
|
+
_data.EdmMapping.action('SendMessage', 'AccommodationRequestActionMessage'), _dec18 =
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
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
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
_data.EdmMapping.action('Cancel', 'AccommodationRequestAction'), (_class = class AccommodationRequestAction extends _EnableAttachmentModel.default {constructor() {super();} /**
|
|
170
|
+
* Adds an attachment
|
|
171
|
+
* @param {*} file
|
|
172
|
+
* @param {*=} extraAttributes
|
|
173
|
+
*/async addAttachment(file, extraAttributes) {const attachment = Object.assign({ name: file.contentFileName }, file, extraAttributes);return await super.addAttachment(attachment);} /**
|
|
174
|
+
* Removes an attachment
|
|
175
|
+
* @param {*} attachment
|
|
176
|
+
*/async removeAttachment(attachment) {return await super.removeAttachment(attachment.id);} /**
|
|
177
|
+
* Rejects an attachment
|
|
178
|
+
* @param {*} attachment
|
|
179
|
+
*/async rejectAttachment(attachment) {return await super.rejectAttachment(attachment.id);} /**
|
|
180
|
+
* Reverts (re-accepts) an attachment
|
|
181
|
+
* @param {*} attachment
|
|
182
|
+
*/async revertAttachment(attachment) {return await super.revertAttachment(attachment.id);} /**
|
|
183
|
+
* Add action messages
|
|
184
|
+
* @param {Array<any>} items
|
|
185
|
+
*/async postMessages(item) {// set initiator
|
|
186
|
+
item.action = this.getId();return this.context.model('AccommodationRequestActionMessage').save(item);} /**
|
|
187
|
+
* Gets item review
|
|
188
|
+
*/getReview() {return this.context.model('AccommodationRequestActionReview').where('itemReviewed').equal(this.getId()).prepare();} /**
|
|
189
|
+
* Set item review
|
|
190
|
+
* @param {*} item
|
|
191
|
+
*/async setReview(item) {const AccommodationRequestActionReviews = this.context.model('AccommodationRequestActionReview'); // infer object state
|
|
192
|
+
const currentReview = await AccommodationRequestActionReviews.where('itemReviewed').equal(this.getId()).getItem();if (currentReview == null) {if (item == null) {return;} // a new item is going to be inserted
|
|
193
|
+
delete item.id; // set reviewed item
|
|
194
|
+
item.itemReviewed = this.getId();} else {if (item == null) {// delete review
|
|
195
|
+
AccommodationRequestActionReviews.remove(currentReview);} // up
|
|
196
|
+
item.id = currentReview.id; // set reviewed item
|
|
197
|
+
item.itemReviewed = this.getId();}return AccommodationRequestActionReviews.save(item);} /**
|
|
198
|
+
* Adds an attachment
|
|
199
|
+
* @param {{contentFileName:string}|*} attachment
|
|
200
|
+
* @param {*=} message
|
|
201
|
+
*/sendMessage(attachment, message) {const thisArg = this;return new Promise((resolve, reject) => {this.context.db.executeInTransaction((cb) => {(async () => {const AccommodationRequestActionMessage = thisArg.context.model('AccommodationRequestActionMessage');if (message.recipient) {// try to find the message recipient by bypassing privileges
|
|
202
|
+
// note: Students do not-and should not-have read access to Account or User models.
|
|
203
|
+
// this process will help to identify an account by its name, e.g. recipient: 'AccommodationUsers'
|
|
204
|
+
const recipient = (await thisArg.context.model('Account').where('name').equal(message.recipient.name || message.recipient).select('id').silent().value()) ?? (await thisArg.context.model('Account').where('id').equal(message.recipient.id || message.recipient).select('id').silent().value());if (recipient == null) {throw new _common.DataError('The specified message recipient (User/Account) cannot be found.');} // and override the message recipient
|
|
205
|
+
message.recipient = recipient;}const newMessage = AccommodationRequestActionMessage.convert(message);Object.assign(newMessage, { action: thisArg.getId() }); // add message
|
|
206
|
+
await AccommodationRequestActionMessage.silent().save(newMessage); // if message has an attachment
|
|
207
|
+
if (attachment) {// prepare attachment data
|
|
208
|
+
const newAttachment = Object.assign({ name: attachment.contentFileName }, attachment); // and add attachment
|
|
209
|
+
await newMessage.addAttachment(newAttachment);}})().then(() => {return cb();}).catch((err) => {return cb(err);});}, (err) => {if (err) {return reject(err);}return resolve(message);});});} //remove accommodation request action
|
|
210
|
+
async cancel() {/**
|
|
211
|
+
* @type {import('@themost/data').DataModel}
|
|
212
|
+
*/const model = this.getModel();const item = await model.where('owner/name').equal(this.context.user.name).and('actionStatus/alternateName').equal('PotentialActionStatus').and('id').equal(this.getId()).getItem();if (item == null) {throw new _common.HttpForbiddenError();}return model.silent().remove(item); // silent() is used to bypass privileges
|
|
213
|
+
}}, (_applyDecoratedDescriptor(_class.prototype, "addAttachment", [_dec, _dec2, _dec3], Object.getOwnPropertyDescriptor(_class.prototype, "addAttachment"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "removeAttachment", [_dec4, _dec5], Object.getOwnPropertyDescriptor(_class.prototype, "removeAttachment"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "rejectAttachment", [_dec6, _dec7], Object.getOwnPropertyDescriptor(_class.prototype, "rejectAttachment"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "revertAttachment", [_dec8, _dec9], Object.getOwnPropertyDescriptor(_class.prototype, "revertAttachment"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "postMessages", [_dec10, _dec11], Object.getOwnPropertyDescriptor(_class.prototype, "postMessages"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "getReview", [_dec12], Object.getOwnPropertyDescriptor(_class.prototype, "getReview"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "setReview", [_dec13, _dec14], Object.getOwnPropertyDescriptor(_class.prototype, "setReview"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "sendMessage", [_dec15, _dec16, _dec17], Object.getOwnPropertyDescriptor(_class.prototype, "sendMessage"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "cancel", [_dec18], Object.getOwnPropertyDescriptor(_class.prototype, "cancel"), _class.prototype)), _class));module.exports = AccommodationRequestAction;
|
|
214
|
+
//# sourceMappingURL=AccommodationRequestAction.js.map
|