@things-factory/notification 9.0.0-beta.8 → 9.0.2
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/dist-client/actions/notification-fcm.js +1 -2
- package/dist-client/actions/notification-fcm.js.map +1 -1
- package/dist-client/bootstrap.js +4 -1
- package/dist-client/bootstrap.js.map +1 -1
- package/dist-client/pages/notification/notification-list-page.js +35 -28
- package/dist-client/pages/notification/notification-list-page.js.map +1 -1
- package/dist-client/pages/notification-rule/notification-rule-importer.js +16 -17
- package/dist-client/pages/notification-rule/notification-rule-importer.js.map +1 -1
- package/dist-client/pages/notification-rule/notification-rule-list-page.js +35 -28
- package/dist-client/pages/notification-rule/notification-rule-list-page.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/viewparts/notification-badge.js +10 -10
- package/dist-client/viewparts/notification-badge.js.map +1 -1
- package/dist-client/viewparts/notification-item.js +78 -79
- package/dist-client/viewparts/notification-item.js.map +1 -1
- package/dist-client/viewparts/notification-list.js +57 -54
- package/dist-client/viewparts/notification-list.js.map +1 -1
- package/dist-client/viewparts/notification-sender.js +55 -56
- package/dist-client/viewparts/notification-sender.js.map +1 -1
- package/dist-client/viewparts/notification-setting-let.js +53 -53
- package/dist-client/viewparts/notification-setting-let.js.map +1 -1
- package/dist-server/controllers/fcm.js +4 -1
- package/dist-server/controllers/fcm.js.map +1 -1
- package/dist-server/routers/notification-router.js +5 -2
- package/dist-server/routers/notification-router.js.map +1 -1
- package/dist-server/service/index.js +6 -2
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/notification/directive-notification.js +1 -2
- package/dist-server/service/notification/directive-notification.js.map +1 -1
- package/dist-server/service/notification/notification-mutation.js +24 -6
- package/dist-server/service/notification/notification-mutation.js.map +1 -1
- package/dist-server/service/notification/notification-subscription.js +2 -2
- package/dist-server/service/notification/notification-subscription.js.map +1 -1
- package/dist-server/service/notification-rule/notification-rule-mutation.js +25 -7
- package/dist-server/service/notification-rule/notification-rule-mutation.js.map +1 -1
- package/dist-server/service/notification-rule/notification-rule-query.js +1 -1
- package/dist-server/service/notification-rule/notification-rule-query.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
|
@@ -11,6 +11,59 @@ import { notify, openPopup } from '@operato/layout';
|
|
|
11
11
|
import { i18next, localize } from '@operato/i18n';
|
|
12
12
|
import { getSubscriptionToken, isSupportingMessaging, subscribe, unsubscribe } from '../actions/notification-fcm';
|
|
13
13
|
let NotificationSettingLet = class NotificationSettingLet extends localize(i18next)(LitElement) {
|
|
14
|
+
static { this.styles = [
|
|
15
|
+
css `
|
|
16
|
+
div[onoff] {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
border-bottom: var(--border-dim-color);
|
|
20
|
+
margin-bottom: var(--spacing-medium);
|
|
21
|
+
padding-bottom: var(--spacing-medium);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
div[info] {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
position: relative;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
label {
|
|
31
|
+
display: flex;
|
|
32
|
+
gap: 10px;
|
|
33
|
+
align-items: center;
|
|
34
|
+
|
|
35
|
+
font: var(--label-font);
|
|
36
|
+
color: var(--md-sys-color-on-surface);
|
|
37
|
+
text-transform: var(--label-text-transform);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
[test] {
|
|
41
|
+
margin-left: auto;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
input {
|
|
45
|
+
border: var(--border-dim-color);
|
|
46
|
+
border-radius: var(--border-radius);
|
|
47
|
+
margin: var(--input-margin);
|
|
48
|
+
padding: var(--input-padding);
|
|
49
|
+
font: var(--input-font);
|
|
50
|
+
|
|
51
|
+
flex: 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
[button-in-field] {
|
|
55
|
+
--md-icon-size: 18px;
|
|
56
|
+
position: absolute;
|
|
57
|
+
top: 24px;
|
|
58
|
+
right: 4px;
|
|
59
|
+
width: 30px;
|
|
60
|
+
padding: 2px;
|
|
61
|
+
border-radius: var(--border-radius, 5px);
|
|
62
|
+
color: var(--md-sys-color-on-secondary, #fff);
|
|
63
|
+
background-color: var(--md-sys-color-secondary, #394e64);
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
]; }
|
|
14
67
|
render() {
|
|
15
68
|
const supported = !!this.supported;
|
|
16
69
|
return html `
|
|
@@ -147,59 +200,6 @@ let NotificationSettingLet = class NotificationSettingLet extends localize(i18ne
|
|
|
147
200
|
});
|
|
148
201
|
}
|
|
149
202
|
};
|
|
150
|
-
NotificationSettingLet.styles = [
|
|
151
|
-
css `
|
|
152
|
-
div[onoff] {
|
|
153
|
-
display: flex;
|
|
154
|
-
align-items: center;
|
|
155
|
-
border-bottom: var(--border-dim-color);
|
|
156
|
-
margin-bottom: var(--spacing-medium);
|
|
157
|
-
padding-bottom: var(--spacing-medium);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
div[info] {
|
|
161
|
-
display: flex;
|
|
162
|
-
flex-direction: column;
|
|
163
|
-
position: relative;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
label {
|
|
167
|
-
display: flex;
|
|
168
|
-
gap: 10px;
|
|
169
|
-
align-items: center;
|
|
170
|
-
|
|
171
|
-
font: var(--label-font);
|
|
172
|
-
color: var(--md-sys-color-on-surface);
|
|
173
|
-
text-transform: var(--label-text-transform);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
[test] {
|
|
177
|
-
margin-left: auto;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
input {
|
|
181
|
-
border: var(--border-dim-color);
|
|
182
|
-
border-radius: var(--border-radius);
|
|
183
|
-
margin: var(--input-margin);
|
|
184
|
-
padding: var(--input-padding);
|
|
185
|
-
font: var(--input-font);
|
|
186
|
-
|
|
187
|
-
flex: 1;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
[button-in-field] {
|
|
191
|
-
--md-icon-size: 18px;
|
|
192
|
-
position: absolute;
|
|
193
|
-
top: 24px;
|
|
194
|
-
right: 4px;
|
|
195
|
-
width: 30px;
|
|
196
|
-
padding: 2px;
|
|
197
|
-
border-radius: var(--border-radius, 5px);
|
|
198
|
-
color: var(--md-sys-color-on-secondary, #fff);
|
|
199
|
-
background-color: var(--md-sys-color-secondary, #394e64);
|
|
200
|
-
}
|
|
201
|
-
`
|
|
202
|
-
];
|
|
203
203
|
__decorate([
|
|
204
204
|
property({ type: Object }),
|
|
205
205
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-setting-let.js","sourceRoot":"","sources":["../../client/viewparts/notification-setting-let.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,gCAAgC,CAAA;AACvC,OAAO,0BAA0B,CAAA;AACjC,OAAO,8BAA8B,CAAA;AACrC,OAAO,uBAAuB,CAAA;AAE9B,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAG1G,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IA4DvE,MAAM;QACJ,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;QAElC,OAAO,IAAI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EAAE,CAAC;;4DAAmB;AACjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;yDAAoB;AAxDrC,sBAAsB;IADlC,aAAa,CAAC,0BAA0B,CAAC;GAC7B,sBAAsB,CA6MlC","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/switch/switch.js'\nimport '@operato/i18n/ox-i18n.js'\nimport '@things-factory/setting-base'\nimport './notification-sender'\n\nimport Clipboard from 'clipboard'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { notify, openPopup } from '@operato/layout'\nimport { i18next, localize } from '@operato/i18n'\n\nimport { getSubscriptionToken, isSupportingMessaging, subscribe, unsubscribe } from '../actions/notification-fcm'\n\n@customElement('notification-setting-let')\nexport class NotificationSettingLet extends localize(i18next)(LitElement) {\n static styles = [\n css`\n div[onoff] {\n display: flex;\n align-items: center;\n border-bottom: var(--border-dim-color);\n margin-bottom: var(--spacing-medium);\n padding-bottom: var(--spacing-medium);\n }\n\n div[info] {\n display: flex;\n flex-direction: column;\n position: relative;\n }\n\n label {\n display: flex;\n gap: 10px;\n align-items: center;\n\n font: var(--label-font);\n color: var(--md-sys-color-on-surface);\n text-transform: var(--label-text-transform);\n }\n\n [test] {\n margin-left: auto;\n }\n\n input {\n border: var(--border-dim-color);\n border-radius: var(--border-radius);\n margin: var(--input-margin);\n padding: var(--input-padding);\n font: var(--input-font);\n\n flex: 1;\n }\n\n [button-in-field] {\n --md-icon-size: 18px;\n position: absolute;\n top: 24px;\n right: 4px;\n width: 30px;\n padding: 2px;\n border-radius: var(--border-radius, 5px);\n color: var(--md-sys-color-on-secondary, #fff);\n background-color: var(--md-sys-color-secondary, #394e64);\n }\n `\n ]\n\n @property({ type: Object }) subscription?: any\n @property({ type: Boolean }) supported?: boolean\n\n clipboard: any\n\n render() {\n const supported = !!this.supported\n\n return html`\n <setting-let>\n <ox-i18n slot=\"title\" msgid=\"title.notification subscription\"></ox-i18n>\n\n ${supported\n ? html`\n <div slot=\"content\" onoff>\n <label>\n <md-switch\n label=\"allow message\"\n ?selected=${!!this.subscription}\n @click=${e => this.onClickSwitch(e)}\n ></md-switch>\n ${String(i18next.t('label.allow push message'))}\n </label>\n <md-outlined-button test @click=${e => this.ontest()}\n >${String(i18next.t('button.push message test'))}</md-outlined-button\n >\n </div>\n\n <div slot=\"content\" info>\n <label for=\"subscription-token\"><ox-i18n msgid=\"label.subscription token\"></ox-i18n></label>\n <input\n id=\"subscription-token\"\n type=\"text\"\n name=\"subscription-token\"\n .value=${this.subscription || ''}\n readonly\n />\n <md-icon button-in-field clipboard-copy @click=${e => e.preventDefault()}>content_copy</md-icon>\n </div>\n `\n : html` <div slot=\"content\">${i18next.t('text.push notification is not supported in your browser')}</div>`}\n </setting-let>\n `\n }\n\n updated(changes) {\n if (changes.has('supported') && this.supported) {\n const copybuttons = this.renderRoot.querySelectorAll('[clipboard-copy]')\n\n this.clipboard = new Clipboard(copybuttons, {\n target: trigger => trigger.parentElement!.querySelector('input')!\n })\n }\n }\n\n async connectedCallback() {\n super.connectedCallback()\n\n if (!('Notification' in window)) {\n return\n }\n\n this.supported = await isSupportingMessaging()\n this.subscription = await getSubscriptionToken()\n }\n\n async onClickSwitch(e) {\n const target = e.target\n const on = target.selected\n\n if (!('Notification' in window)) {\n notify({\n level: 'error',\n message: i18next.t('This browser does not support desktop notification')\n })\n\n return\n }\n\n try {\n if (Notification.permission !== 'granted') {\n const permission = await Notification.requestPermission()\n if (permission === 'denied') {\n notify({\n level: 'error',\n message: i18next.t('text.web push notification unblock guide')\n })\n }\n return\n }\n\n if (Notification.permission === 'granted') {\n if (on) {\n const subscription = await getSubscriptionToken()\n\n if (subscription) {\n this.subscription = subscription\n notify({\n level: 'info',\n message: i18next.t('text.notification subscribed already')\n })\n } else {\n this.subscription = await subscribe()\n\n this.subscription &&\n notify({\n level: 'info',\n message: i18next.t('text.notification subscribe started')\n })\n }\n } else {\n if (this.subscription) {\n await unsubscribe()\n\n this.subscription = await getSubscriptionToken()\n\n notify({\n level: 'info',\n message: i18next.t('text.notification unsubscribed')\n })\n } else {\n notify({\n level: 'info',\n message: i18next.t('text.notification unsubscribed already')\n })\n }\n }\n } else {\n notify({\n level: 'error',\n message: i18next.t('text.notification subscribing failed')\n })\n }\n } catch (err) {\n notify({\n level: 'error',\n message: String(err)\n })\n } finally {\n target.checked = !!this.subscription\n }\n }\n\n ontest() {\n openPopup(html` <notification-sender></notification-sender> `, {\n backdrop: true,\n size: 'large',\n title: i18next.t('title.notification-sender')\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notification-setting-let.js","sourceRoot":"","sources":["../../client/viewparts/notification-setting-let.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,gCAAgC,CAAA;AACvC,OAAO,0BAA0B,CAAA;AACjC,OAAO,8BAA8B,CAAA;AACrC,OAAO,uBAAuB,CAAA;AAE9B,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAG1G,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;aAChE,WAAM,GAAG;QACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkDF;KACF,AApDY,CAoDZ;IAOD,MAAM;QACJ,MAAM,SAAS,GAAG,CAAC,C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E,CAAC;;yDAAoB;AAxDrC,sBAAsB;IADlC,aAAa,CAAC,0BAA0B,CAAC;GAC7B,sBAAsB,CA6MlC","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/switch/switch.js'\nimport '@operato/i18n/ox-i18n.js'\nimport '@things-factory/setting-base'\nimport './notification-sender'\n\nimport Clipboard from 'clipboard'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { notify, openPopup } from '@operato/layout'\nimport { i18next, localize } from '@operato/i18n'\n\nimport { getSubscriptionToken, isSupportingMessaging, subscribe, unsubscribe } from '../actions/notification-fcm'\n\n@customElement('notification-setting-let')\nexport class NotificationSettingLet extends localize(i18next)(LitElement) {\n static styles = [\n css`\n div[onoff] {\n display: flex;\n align-items: center;\n border-bottom: var(--border-dim-color);\n margin-bottom: var(--spacing-medium);\n padding-bottom: var(--spacing-medium);\n }\n\n div[info] {\n display: flex;\n flex-direction: column;\n position: relative;\n }\n\n label {\n display: flex;\n gap: 10px;\n align-items: center;\n\n font: var(--label-font);\n color: var(--md-sys-color-on-surface);\n text-transform: var(--label-text-transform);\n }\n\n [test] {\n margin-left: auto;\n }\n\n input {\n border: var(--border-dim-color);\n border-radius: var(--border-radius);\n margin: var(--input-margin);\n padding: var(--input-padding);\n font: var(--input-font);\n\n flex: 1;\n }\n\n [button-in-field] {\n --md-icon-size: 18px;\n position: absolute;\n top: 24px;\n right: 4px;\n width: 30px;\n padding: 2px;\n border-radius: var(--border-radius, 5px);\n color: var(--md-sys-color-on-secondary, #fff);\n background-color: var(--md-sys-color-secondary, #394e64);\n }\n `\n ]\n\n @property({ type: Object }) subscription?: any\n @property({ type: Boolean }) supported?: boolean\n\n clipboard: any\n\n render() {\n const supported = !!this.supported\n\n return html`\n <setting-let>\n <ox-i18n slot=\"title\" msgid=\"title.notification subscription\"></ox-i18n>\n\n ${supported\n ? html`\n <div slot=\"content\" onoff>\n <label>\n <md-switch\n label=\"allow message\"\n ?selected=${!!this.subscription}\n @click=${e => this.onClickSwitch(e)}\n ></md-switch>\n ${String(i18next.t('label.allow push message'))}\n </label>\n <md-outlined-button test @click=${e => this.ontest()}\n >${String(i18next.t('button.push message test'))}</md-outlined-button\n >\n </div>\n\n <div slot=\"content\" info>\n <label for=\"subscription-token\"><ox-i18n msgid=\"label.subscription token\"></ox-i18n></label>\n <input\n id=\"subscription-token\"\n type=\"text\"\n name=\"subscription-token\"\n .value=${this.subscription || ''}\n readonly\n />\n <md-icon button-in-field clipboard-copy @click=${e => e.preventDefault()}>content_copy</md-icon>\n </div>\n `\n : html` <div slot=\"content\">${i18next.t('text.push notification is not supported in your browser')}</div>`}\n </setting-let>\n `\n }\n\n updated(changes) {\n if (changes.has('supported') && this.supported) {\n const copybuttons = this.renderRoot.querySelectorAll('[clipboard-copy]')\n\n this.clipboard = new Clipboard(copybuttons, {\n target: trigger => trigger.parentElement!.querySelector('input')!\n })\n }\n }\n\n async connectedCallback() {\n super.connectedCallback()\n\n if (!('Notification' in window)) {\n return\n }\n\n this.supported = await isSupportingMessaging()\n this.subscription = await getSubscriptionToken()\n }\n\n async onClickSwitch(e) {\n const target = e.target\n const on = target.selected\n\n if (!('Notification' in window)) {\n notify({\n level: 'error',\n message: i18next.t('This browser does not support desktop notification')\n })\n\n return\n }\n\n try {\n if (Notification.permission !== 'granted') {\n const permission = await Notification.requestPermission()\n if (permission === 'denied') {\n notify({\n level: 'error',\n message: i18next.t('text.web push notification unblock guide')\n })\n }\n return\n }\n\n if (Notification.permission === 'granted') {\n if (on) {\n const subscription = await getSubscriptionToken()\n\n if (subscription) {\n this.subscription = subscription\n notify({\n level: 'info',\n message: i18next.t('text.notification subscribed already')\n })\n } else {\n this.subscription = await subscribe()\n\n this.subscription &&\n notify({\n level: 'info',\n message: i18next.t('text.notification subscribe started')\n })\n }\n } else {\n if (this.subscription) {\n await unsubscribe()\n\n this.subscription = await getSubscriptionToken()\n\n notify({\n level: 'info',\n message: i18next.t('text.notification unsubscribed')\n })\n } else {\n notify({\n level: 'info',\n message: i18next.t('text.notification unsubscribed already')\n })\n }\n }\n } else {\n notify({\n level: 'error',\n message: i18next.t('text.notification subscribing failed')\n })\n }\n } catch (err) {\n notify({\n level: 'error',\n message: String(err)\n })\n } finally {\n target.checked = !!this.subscription\n }\n }\n\n ontest() {\n openPopup(html` <notification-sender></notification-sender> `, {\n backdrop: true,\n size: 'large',\n title: i18next.t('title.notification-sender')\n })\n }\n}\n"]}
|
|
@@ -45,7 +45,10 @@ async function sendNotification({ receivers, message }) {
|
|
|
45
45
|
if (!messaging) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
notify(
|
|
48
|
+
notify({
|
|
49
|
+
receivers,
|
|
50
|
+
...message
|
|
51
|
+
});
|
|
49
52
|
}
|
|
50
53
|
async function register(user, { subscription }) {
|
|
51
54
|
if (!messaging || !subscription || !user) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fcm.js","sourceRoot":"","sources":["../../server/controllers/fcm.ts"],"names":[],"mappings":";;AA2BA,8BAOC;AAQD,4CASC;AAED,4BA2BC;AAED,gCAqBC;AAED,wBAsEC;;AA/KD,oEAA8B;AAE9B,6CAAoD;AAEpD,4CAAwD;AACxD,wDAAuD;AAEvD,MAAM,kBAAkB,GAAG,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;AAC3D,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,kBAAkB,CAAA;AAC5C,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,CAAA;AAC1D,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,IAAI,EAAE,CAAA;AAEpC,IAAI,SAAS,CAAA;AAEb,IAAI,cAAc,EAAE,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAA,mBAAa,EAAC;YACxB,UAAU,EAAE,IAAA,UAAI,EAAC,cAAc,CAAC;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E,EAAE,CAAC;QAChB,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClD,OAAO,gBAAgB,CAAA;IACzB,CAAC;AACH,CAAC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { config, logger } from '@things-factory/env'\n\nimport { initializeApp, cert } from 'firebase-admin/app'\nimport { getMessaging } from 'firebase-admin/messaging'\n\nconst notificationConfig = config.get('notification') || {}\nconst { fcm, vapidKey } = notificationConfig\nconst { serviceAccount, appConfig, serverKey } = fcm || {}\nconst { publicKey } = vapidKey || {}\n\nvar messaging\n\nif (serviceAccount) {\n try {\n const app = initializeApp({\n credential: cert(serviceAccount)\n })\n\n messaging = getMessaging(app)\n } catch (err) {\n logger.error('incorrect notification configuration')\n logger.error(err)\n }\n}\n\nexport function getConfig() {\n return messaging\n ? {\n appConfig,\n vapidPublicKey: publicKey\n }\n : {}\n}\n\n/**\n * sendNotification\n *\n * @param receiver user.id who will receive notification\n * @param message message object to be sent\n */\nexport async function sendNotification({ receivers, message }) {\n if (!messaging) {\n return\n }\n\n notify({\n receivers,\n ...message\n })\n}\n\nexport async function register(user, { subscription }) {\n if (!messaging || !subscription || !user) {\n return false\n }\n\n try {\n var notification_key = await getDeviceGroup(user.id)\n\n if (!notification_key) {\n await postDeviceGroup({\n operation: 'create',\n notification_key_name: user.id,\n registration_ids: [subscription]\n })\n } else {\n await postDeviceGroup({\n operation: 'add',\n notification_key_name: user.id,\n notification_key,\n registration_ids: [subscription]\n })\n }\n\n return true\n } catch (err) {\n return\n }\n}\n\nexport async function unregister(user, { subscription }) {\n if (!messaging || !subscription || !user) {\n return false\n }\n\n try {\n var notification_key = await getDeviceGroup(user.id)\n\n if (notification_key) {\n await postDeviceGroup({\n operation: 'remove',\n notification_key_name: user.id,\n notification_key,\n registration_ids: [subscription]\n })\n }\n\n return true\n } catch (err) {\n return\n }\n}\n\nexport async function notify({ receivers, privileges, tokens, topic, title, body, data, image, actions }) {\n if (!messaging) {\n return\n }\n\n // Caution: non-string attributes are not allowed in FCM payload validation\n var notification = {\n title: title || '',\n body: body || '',\n image: image || ''\n }\n\n if (tokens && tokens instanceof Array && tokens.length > 0) {\n if (tokens.length > 1) {\n const response = await messaging.sendMulticast({\n notification,\n data,\n tokens\n })\n\n if (response.failureCount > 0) {\n const failedTokens = []\n response.responses.forEach((resp, idx) => {\n if (!resp.success) {\n failedTokens.push(tokens[idx])\n }\n })\n logger.error('List of tokens that caused failures: ' + failedTokens)\n }\n } else {\n const token = tokens[0]\n\n try {\n const response = await messaging.send({\n notification,\n data,\n token\n })\n logger.log('Successfully sent message:', response)\n } catch (err) {\n logger.error('Error sending message:', err)\n }\n }\n }\n\n if (topic) {\n try {\n const response = await messaging.send({\n notification,\n data,\n topic\n })\n logger.log('Successfully sent message:', response)\n } catch (err) {\n logger.error('Error sending message:', err)\n }\n }\n\n if (receivers && receivers instanceof Array) {\n for (let receiver of receivers) {\n const notification_key = await getDeviceGroup(receiver)\n\n if (notification_key) {\n await messaging.sendToDeviceGroup(notification_key, {\n notification,\n data\n })\n }\n }\n }\n}\n\nasync function postDeviceGroup(body) {\n var response = await fetch('https://fcm.googleapis.com/fcm/notification', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `key=${serverKey}`,\n project_id: appConfig.messagingSenderId\n },\n body: JSON.stringify(body)\n })\n\n if (response.ok) {\n const { notification_key } = await response.json()\n return notification_key\n } else {\n console.error('postDeviceGroup-notok', response.status, await response.text())\n }\n}\n\nasync function getDeviceGroup(notificationKeyName) {\n const response = await fetch(\n `https://fcm.googleapis.com/fcm/notification?notification_key_name=${notificationKeyName}`,\n {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `key=${serverKey}`,\n project_id: appConfig.messagingSenderId\n }\n }\n )\n\n if (response.ok) {\n const { notification_key } = await response.json()\n return notification_key\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fcm.js","sourceRoot":"","sources":["../../server/contro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C3B,CAAC,CAAA;IAEF,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;QAChB,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClD,OAAO,gBAAgB,CAAA;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAChF,CAAC;AACH,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,mBAAmB;IAC/C,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAC1B,qEAAqE,mBAAmB,EAAE,EAC1F;QACE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,OAAO,SAAS,EAAE;YACjC,UAAU,EAAE,SAAS,CAAC,iBAAiB;SACxC;KACF,CACF,CAAA;IAED,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;QAChB,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClD,OAAO,gBAAgB,CAAA;IACzB,CAAC;AACH,CAAC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { config, logger } from '@things-factory/env'\n\nimport { initializeApp, cert } from 'firebase-admin/app'\nimport { getMessaging } from 'firebase-admin/messaging'\n\nconst notificationConfig = config.get('notification') || {}\nconst { fcm, vapidKey } = notificationConfig\nconst { serviceAccount, appConfig, serverKey } = fcm || {}\nconst { publicKey } = vapidKey || {}\n\nvar messaging\n\nif (serviceAccount) {\n try {\n const app = initializeApp({\n credential: cert(serviceAccount)\n })\n\n messaging = getMessaging(app)\n } catch (err) {\n logger.error('incorrect notification configuration')\n logger.error(err)\n }\n}\n\nexport function getConfig() {\n return messaging\n ? {\n appConfig,\n vapidPublicKey: publicKey\n }\n : {}\n}\n\n/**\n * sendNotification\n *\n * @param receiver user.id who will receive notification\n * @param message message object to be sent\n */\nexport async function sendNotification({ receivers, message }) {\n if (!messaging) {\n return\n }\n\n notify({\n receivers,\n ...message\n })\n}\n\nexport async function register(user, { subscription }) {\n if (!messaging || !subscription || !user) {\n return false\n }\n\n try {\n var notification_key = await getDeviceGroup(user.id)\n\n if (!notification_key) {\n await postDeviceGroup({\n operation: 'create',\n notification_key_name: user.id,\n registration_ids: [subscription]\n })\n } else {\n await postDeviceGroup({\n operation: 'add',\n notification_key_name: user.id,\n notification_key,\n registration_ids: [subscription]\n })\n }\n\n return true\n } catch (err) {\n return\n }\n}\n\nexport async function unregister(user, { subscription }) {\n if (!messaging || !subscription || !user) {\n return false\n }\n\n try {\n var notification_key = await getDeviceGroup(user.id)\n\n if (notification_key) {\n await postDeviceGroup({\n operation: 'remove',\n notification_key_name: user.id,\n notification_key,\n registration_ids: [subscription]\n })\n }\n\n return true\n } catch (err) {\n return\n }\n}\n\nexport async function notify({ receivers, privileges, tokens, topic, title, body, data, image, actions }) {\n if (!messaging) {\n return\n }\n\n // Caution: non-string attributes are not allowed in FCM payload validation\n var notification = {\n title: title || '',\n body: body || '',\n image: image || ''\n }\n\n if (tokens && tokens instanceof Array && tokens.length > 0) {\n if (tokens.length > 1) {\n const response = await messaging.sendMulticast({\n notification,\n data,\n tokens\n })\n\n if (response.failureCount > 0) {\n const failedTokens = []\n response.responses.forEach((resp, idx) => {\n if (!resp.success) {\n failedTokens.push(tokens[idx])\n }\n })\n logger.error('List of tokens that caused failures: ' + failedTokens)\n }\n } else {\n const token = tokens[0]\n\n try {\n const response = await messaging.send({\n notification,\n data,\n token\n })\n logger.log('Successfully sent message:', response)\n } catch (err) {\n logger.error('Error sending message:', err)\n }\n }\n }\n\n if (topic) {\n try {\n const response = await messaging.send({\n notification,\n data,\n topic\n })\n logger.log('Successfully sent message:', response)\n } catch (err) {\n logger.error('Error sending message:', err)\n }\n }\n\n if (receivers && receivers instanceof Array) {\n for (let receiver of receivers) {\n const notification_key = await getDeviceGroup(receiver)\n\n if (notification_key) {\n await messaging.sendToDeviceGroup(notification_key, {\n notification,\n data\n })\n }\n }\n }\n}\n\nasync function postDeviceGroup(body) {\n var response = await fetch('https://fcm.googleapis.com/fcm/notification', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `key=${serverKey}`,\n project_id: appConfig.messagingSenderId\n },\n body: JSON.stringify(body)\n })\n\n if (response.ok) {\n const { notification_key } = await response.json()\n return notification_key\n } else {\n console.error('postDeviceGroup-notok', response.status, await response.text())\n }\n}\n\nasync function getDeviceGroup(notificationKeyName) {\n const response = await fetch(\n `https://fcm.googleapis.com/fcm/notification?notification_key_name=${notificationKeyName}`,\n {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `key=${serverKey}`,\n project_id: appConfig.messagingSenderId\n }\n }\n )\n\n if (response.ok) {\n const { notification_key } = await response.json()\n return notification_key\n }\n}\n"]}
|
|
@@ -31,7 +31,7 @@ exports.notificationRouter.post('/unregister', async (context, next) => {
|
|
|
31
31
|
exports.notificationRouter.post('/notify', async (context, next) => {
|
|
32
32
|
const { user, domain, notify } = context.state;
|
|
33
33
|
const repository = (0, shell_1.getRepository)(auth_base_1.User);
|
|
34
|
-
var
|
|
34
|
+
var { receivers, ...options } = context.request.body;
|
|
35
35
|
debug('post:/notify', receivers, receivers.split(','), options);
|
|
36
36
|
// TODO filter only users having current domain privilege
|
|
37
37
|
receivers = (await Promise.all(receivers
|
|
@@ -42,7 +42,10 @@ exports.notificationRouter.post('/notify', async (context, next) => {
|
|
|
42
42
|
return receiver && receiver.id;
|
|
43
43
|
}))).filter(receiver => !!receiver);
|
|
44
44
|
debug('post:/notify', receivers, user.id);
|
|
45
|
-
await notify(
|
|
45
|
+
await notify({
|
|
46
|
+
receivers: receivers.length > 0 ? receivers : [user.id],
|
|
47
|
+
...options
|
|
48
|
+
});
|
|
46
49
|
context.body = {
|
|
47
50
|
success: true
|
|
48
51
|
};
|
|
@@ -1 +1 @@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AC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;IAEhC,KAAK,CAAC,cAAc,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;IAEzC,MAAM,MAAM,CAAC;QACX,SAAS,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,GAAG,OAAO;KACX,CAAC,CAAA;IAEF,OAAO,CAAC,IAAI,GAAG;QACb,OAAO,EAAE,IAAI;KACd,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport { ILike } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { getRepository } from '@things-factory/shell'\n\nimport { getConfig, register, unregister } from '../controllers/fcm'\n\nconst debug = require('debug')('things-factory:notification:notification-router')\n\nexport const notificationRouter = new Router({\n prefix: '/notification'\n})\n\nnotificationRouter.get('/config', async (context, next) => {\n const config = getConfig()\n\n context.type = 'application/json'\n context.body = config\n})\n\nnotificationRouter.post('/register', async (context, next) => {\n const { user } = context.state\n const { body } = context.request\n context.body = await register(user, body)\n context.status = 200\n})\n\nnotificationRouter.post('/unregister', async (context, next) => {\n const { user } = context.state\n const { body } = context.request\n context.body = await unregister(user, body)\n context.status = 200\n})\n\nnotificationRouter.post('/notify', async (context, next) => {\n const { user, domain, notify } = context.state\n const repository = getRepository(User)\n\n var { receivers, ...options } = context.request.body\n\n debug('post:/notify', receivers, receivers.split(','), options)\n\n // TODO filter only users having current domain privilege\n receivers = (\n await Promise.all(\n receivers\n .split(',')\n .map(email => email.trim())\n .map(async email => {\n var receiver: User = await repository.findOneBy({ email: ILike(email) })\n return receiver && receiver.id\n })\n )\n ).filter(receiver => !!receiver)\n\n debug('post:/notify', receivers, user.id)\n\n await notify({\n receivers: receivers.length > 0 ? receivers : [user.id],\n ...options\n })\n\n context.body = {\n success: true\n }\n})\n"]}
|
|
@@ -18,13 +18,17 @@ exports.subscribers = [
|
|
|
18
18
|
...notification_rule_1.subscribers
|
|
19
19
|
];
|
|
20
20
|
exports.schema = {
|
|
21
|
-
typeDefs:
|
|
21
|
+
typeDefs: {
|
|
22
|
+
...notification_1.typeDefs
|
|
23
|
+
},
|
|
22
24
|
resolverClasses: [
|
|
23
25
|
/* RESOLVER CLASSES */
|
|
24
26
|
...notification_rule_1.resolvers,
|
|
25
27
|
...notification_1.resolvers,
|
|
26
28
|
...notification_1.resolvers
|
|
27
29
|
],
|
|
28
|
-
directives:
|
|
30
|
+
directives: {
|
|
31
|
+
...notification_1.directives
|
|
32
|
+
}
|
|
29
33
|
};
|
|
30
34
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yBAAyB;AACzB,gFAAqD;AACrD,sEAA2C;AAE3C,mCAAmC;AACnC,2DAI4B;AAC5B,iDAKuB;AAEV,QAAA,QAAQ,GAAG;IACtB,cAAc;IACd,GAAG,4BAAwB;IAC3B,GAAG,uBAAoB;CACxB,CAAA;AAEY,QAAA,WAAW,GAAG;IACzB,iBAAiB;IACjB,GAAG,+BAA2B;CAC/B,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yBAAyB;AACzB,gFAAqD;AACrD,sEAA2C;AAE3C,mCAAmC;AACnC,2DAI4B;AAC5B,iDAKuB;AAEV,QAAA,QAAQ,GAAG;IACtB,cAAc;IACd,GAAG,4BAAwB;IAC3B,GAAG,uBAAoB;CACxB,CAAA;AAEY,QAAA,WAAW,GAAG;IACzB,iBAAiB;IACjB,GAAG,+BAA2B;CAC/B,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,QAAQ,EAAE;QACR,GAAG,uBAAoB;KACxB;IACD,eAAe,EAAE;QACf,sBAAsB;QACtB,GAAG,6BAAyB;QAC5B,GAAG,wBAAqB;QACxB,GAAG,wBAAqB;KACzB;IACD,UAAU,EAAE;QACV,GAAG,yBAAsB;KAC1B;CACF,CAAA","sourcesContent":["/* EXPORT ENTITY TYPES */\nexport * from './notification-rule/notification-rule'\nexport * from './notification/notification'\n\n/* IMPORT ENTITIES AND RESOLVERS */\nimport {\n entities as NotificationRuleEntities,\n resolvers as NotificationRuleResolvers,\n subscribers as NotificationRuleSubscribers\n} from './notification-rule'\nimport {\n entities as NotificationEntities,\n typeDefs as NotificationTypeDefs,\n resolvers as NotificationResolvers,\n directives as NotificationDirectives\n} from './notification'\n\nexport const entities = [\n /* ENTITIES */\n ...NotificationRuleEntities,\n ...NotificationEntities\n]\n\nexport const subscribers = [\n /* SUBSCRIBERS */\n ...NotificationRuleSubscribers\n]\n\nexport const schema = {\n typeDefs: {\n ...NotificationTypeDefs\n },\n resolverClasses: [\n /* RESOLVER CLASSES */\n ...NotificationRuleResolvers,\n ...NotificationResolvers,\n ...NotificationResolvers\n ],\n directives: {\n ...NotificationDirectives\n }\n}\n"]}
|
|
@@ -22,8 +22,7 @@ exports.notificationDirectiveTypeDefs = (0, graphql_tag_1.default) `
|
|
|
22
22
|
`;
|
|
23
23
|
const directiveNotification = (schema) => (0, utils_1.mapSchema)(schema, {
|
|
24
24
|
[utils_1.MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName, typeName, schema) => {
|
|
25
|
-
|
|
26
|
-
const notificationDirective = (_a = (0, utils_1.getDirective)(schema, fieldConfig, DIRECTIVE)) === null || _a === void 0 ? void 0 : _a[0];
|
|
25
|
+
const notificationDirective = (0, utils_1.getDirective)(schema, fieldConfig, DIRECTIVE)?.[0];
|
|
27
26
|
if (notificationDirective) {
|
|
28
27
|
const { resolve = graphql_1.defaultFieldResolver, args } = fieldConfig;
|
|
29
28
|
if (!args) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directive-notification.js","sourceRoot":"","sources":["../../../server/service/notification/directive-notification.ts"],"names":[],"mappings":";;;;AAAA,qCAA6D;AAC7D,sEAA6B;AAE7B,gDAA0E;AAE1E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAEpF,MAAM,SAAS,GAAG,cAAc,CAAA;AAEnB,QAAA,6BAA6B,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;CAY/C,CAAA;AACM,MAAM,qBAAqB,GAAG,CAAC,MAAqB,EAAE,EAAE,CAC7D,IAAA,iBAAS,EAAC,MAAM,EAAE;IAChB,CAAC,kBAAU,CAAC,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE
|
|
1
|
+
{"version":3,"file":"directive-notification.js","sourceRoot":"","sources":["../../../server/service/notification/directive-notification.ts"],"names":[],"mappings":";;;;AAAA,qCAA6D;AAC7D,sEAA6B;AAE7B,gDAA0E;AAE1E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAEpF,MAAM,SAAS,GAAG,cAAc,CAAA;AAEnB,QAAA,6BAA6B,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;CAY/C,CAAA;AACM,MAAM,qBAAqB,GAAG,CAAC,MAAqB,EAAE,EAAE,CAC7D,IAAA,iBAAS,EAAC,MAAM,EAAE;IAChB,CAAC,kBAAU,CAAC,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE;QACtE,MAAM,qBAAqB,GAAG,IAAA,oBAAY,EAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC/E,IAAI,qBAAqB,EAAE,CAAC;YAC1B,MAAM,EAAE,OAAO,GAAG,8BAAoB,EAAE,IAAI,EAAE,GAAG,WAAW,CAAA;YAE5D,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,iFAAiF,SAAS,GAAG,CAAC,CAAA;YAChH,CAAC;YAED,MAAM,EACJ,SAAS,EACT,KAAK,EACL,OAAO,GAAG,MAAM,EAChB,KAAK,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,IAAI,GAAG,YAAY,EACpB,GAAG,qBAAqB,CAAA;YACzB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAE5B,WAAW,CAAC,OAAO,GAAG,KAAK,WAAW,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI;gBAC/D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;gBAEpE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;gBAE9C,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,KAAK,CAAC,gBAAgB,CAAC,CAAA;gBACzB,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC;wBACH,MAAM,MAAM,CAAC;4BACX,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;4BACpB,qBAAqB;4BACrB,SAAS,EAAE,IAAI,IAAI,EAAE;yBACtB,CAAC,CAAA;oBACJ,CAAC;oBAAC,OAAO,GAAG,EAAE,CAAC;wBACb,KAAK,CAAC,GAAG,CAAC,CAAA;oBACZ,CAAC;gBACH,CAAC;gBAED,OAAO,MAAM,CAAA;YACf,CAAC,CAAA;YAED,OAAO,WAAW,CAAA;QACpB,CAAC;IACH,CAAC;CACF,CAAC,CAAA;AAhDS,QAAA,qBAAqB,yBAgD9B","sourcesContent":["import { defaultFieldResolver, GraphQLSchema } from 'graphql'\nimport gql from 'graphql-tag'\n\nimport { getDirective, MapperKind, mapSchema } from '@graphql-tools/utils'\n\nconst debug = require('debug')('things-factory:notification:directive-notification')\n\nconst DIRECTIVE = 'notification'\n\nexport const notificationDirectiveTypeDefs = gql`\n directive @notification(\n receivers: String\n topic: String\n subject: String # info\n title: String\n body: String\n image: String\n url: String\n # timestamp = String(Date.now())\n mode: String # background\n ) on FIELD_DEFINITION\n`\nexport const directiveNotification = (schema: GraphQLSchema) =>\n mapSchema(schema, {\n [MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName, typeName, schema) => {\n const notificationDirective = getDirective(schema, fieldConfig, DIRECTIVE)?.[0]\n if (notificationDirective) {\n const { resolve = defaultFieldResolver, args } = fieldConfig\n\n if (!args) {\n throw new Error(`Unexpected Error. args should be defined in @notification directive for field ${fieldName}.`)\n }\n\n const {\n receivers,\n topic,\n subject = 'info',\n title,\n body,\n image,\n url,\n mode = 'background'\n } = notificationDirective\n const timestamp = Date.now()\n\n fieldConfig.resolve = async function (source, args, context, info) {\n const result = await resolve.call(this, source, args, context, info)\n\n const { domain, user, notify } = context.state\n\n if (!notify) {\n debug('notify not set')\n } else {\n try {\n await notify({\n receivers: [user.id],\n notificationDirective,\n timestamp: new Date()\n })\n } catch (err) {\n debug(err)\n }\n }\n\n return result\n }\n\n return fieldConfig\n }\n }\n })\n"]}
|
|
@@ -9,7 +9,12 @@ const notification_type_1 = require("./notification-type");
|
|
|
9
9
|
let NotificationMutation = class NotificationMutation {
|
|
10
10
|
async createNotification(notification, context) {
|
|
11
11
|
const { domain, user, tx } = context.state;
|
|
12
|
-
return await tx.getRepository(notification_1.Notification).save(
|
|
12
|
+
return await tx.getRepository(notification_1.Notification).save({
|
|
13
|
+
...notification,
|
|
14
|
+
domain,
|
|
15
|
+
creator: user,
|
|
16
|
+
updater: user
|
|
17
|
+
});
|
|
13
18
|
}
|
|
14
19
|
async updateNotification(id, patch, context) {
|
|
15
20
|
const { domain, user, tx } = context.state;
|
|
@@ -17,7 +22,11 @@ let NotificationMutation = class NotificationMutation {
|
|
|
17
22
|
const notification = await repository.findOne({
|
|
18
23
|
where: { domain: { id: domain.id }, id }
|
|
19
24
|
});
|
|
20
|
-
const result = await repository.save(
|
|
25
|
+
const result = await repository.save({
|
|
26
|
+
...notification,
|
|
27
|
+
...patch,
|
|
28
|
+
updater: user
|
|
29
|
+
});
|
|
21
30
|
return result;
|
|
22
31
|
}
|
|
23
32
|
async updateMultipleNotification(patches, context) {
|
|
@@ -29,16 +38,25 @@ let NotificationMutation = class NotificationMutation {
|
|
|
29
38
|
if (_createRecords.length > 0) {
|
|
30
39
|
for (let i = 0; i < _createRecords.length; i++) {
|
|
31
40
|
const newRecord = _createRecords[i];
|
|
32
|
-
const result = await notificationRepo.save(
|
|
33
|
-
|
|
41
|
+
const result = await notificationRepo.save({
|
|
42
|
+
...newRecord,
|
|
43
|
+
domain,
|
|
44
|
+
creator: user,
|
|
45
|
+
updater: user
|
|
46
|
+
});
|
|
47
|
+
results.push({ ...result, cuFlag: '+' });
|
|
34
48
|
}
|
|
35
49
|
}
|
|
36
50
|
if (_updateRecords.length > 0) {
|
|
37
51
|
for (let i = 0; i < _updateRecords.length; i++) {
|
|
38
52
|
const updateRecord = _updateRecords[i];
|
|
39
53
|
const notification = await notificationRepo.findOneBy({ id: updateRecord.id });
|
|
40
|
-
const result = await notificationRepo.save(
|
|
41
|
-
|
|
54
|
+
const result = await notificationRepo.save({
|
|
55
|
+
...notification,
|
|
56
|
+
...updateRecord,
|
|
57
|
+
updater: user
|
|
58
|
+
});
|
|
59
|
+
results.push({ ...result, cuFlag: 'M' });
|
|
42
60
|
}
|
|
43
61
|
}
|
|
44
62
|
return results;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-mutation.js","sourceRoot":"","sources":["../../../server/service/notification/notification-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAA6C;AAC7C,2DAAwE;AAGjE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAGzB,AAAN,KAAK,CAAC,kBAAkB,CACD,YAA6B,EAC3C,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,2BAAY,CAAC,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"notification-mutation.js","sourceRoot":"","sources":["../../../server/service/notification/notification-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAA6C;AAC7C,2DAAwE;AAGjE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAGzB,AAAN,KAAK,CAAC,kBAAkB,CACD,YAA6B,EAC3C,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,2BAAY,CAAC,CAAC,IAAI,CAAC;YAC/C,GAAG,YAAY;YACf,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC;IAIK,AAAN,KAAK,CAAC,kBAAkB,CACX,EAAU,EACP,KAAwB,EAC/B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,2BAAY,CAAC,CAAA;QACjD,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC5C,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;SACzC,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC;YACnC,GAAG,YAAY;YACf,GAAG,KAAK;YACR,OAAO,EAAE,IAAI;SACd,CA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C,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;gEAUP;+BA9GU,oBAAoB;IADhC,IAAA,uBAAQ,EAAC,2BAAY,CAAC;GACV,oBAAoB,CA+GhC","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { Notification } from './notification'\nimport { NewNotification, NotificationPatch } from './notification-type'\n\n@Resolver(Notification)\nexport class NotificationMutation {\n @Directive('@transaction')\n @Mutation(returns => Notification, { description: 'To create new Notification' })\n async createNotification(\n @Arg('notification') notification: NewNotification,\n @Ctx() context: ResolverContext\n ): Promise<Notification> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Notification).save({\n ...notification,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => Notification, { description: 'To modify Notification information' })\n async updateNotification(\n @Arg('id') id: string,\n @Arg('patch') patch: NotificationPatch,\n @Ctx() context: ResolverContext\n ): Promise<Notification> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Notification)\n const notification = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...notification,\n ...patch,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Notification], { description: \"To modify multiple Notificationes' information\" })\n async updateMultipleNotification(\n @Arg('patches', type => [NotificationPatch]) patches: NotificationPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Notification[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const notificationRepo = tx.getRepository(Notification)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await notificationRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const notification = await notificationRepo.findOneBy({ id: updateRecord.id })\n\n const result = await notificationRepo.save({\n ...notification,\n ...updateRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete Notification' })\n async deleteNotification(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Notification).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple Notificationes' })\n async deleteNotificationes(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Notification).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n}\n"]}
|
|
@@ -20,9 +20,9 @@ tslib_1.__decorate([
|
|
|
20
20
|
/* normally, subscription context doesn't have domain */
|
|
21
21
|
const { domain, user } = context.state;
|
|
22
22
|
const { notification: { subject, domain: pdomain } } = payload;
|
|
23
|
-
const subdomain = pdomain
|
|
23
|
+
const subdomain = pdomain?.subdomain;
|
|
24
24
|
if (subdomain) {
|
|
25
|
-
if (domain
|
|
25
|
+
if (domain?.subdomain) {
|
|
26
26
|
if (subdomain !== domain.subdomain) {
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-subscription.js","sourceRoot":"","sources":["../../../server/service/notification/notification-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAA+E;AAE/E,iDAA0D;AAE1D,iDAA6C;AAGtC,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAgCnC,YAAY,CAAS,OAAuC,EAAyD,QAAkB;QACrI,OAAO,OAAO,CAAC,YAAY,CAAA;IAC7B,CAAC;CACF,CAAA;AAnCY,4DAAwB;AAgCnC;IA/BC,IAAA,2BAAY,EAAC;QACZ,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;YACrC,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,IAAI,CAAA;YAE9B,OAAO,IAAA,mBAAI,EACT,cAAM,CAAC,SAAS,CAAC,cAAc,CAAC,EAChC,IAAA,qBAAM,EAAC,KAAK,EAAE,OAAuC,EAAE,EAAE;gBACvD,wDAAwD;gBACxD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;gBAEtC,MAAM,EACJ,YAAY,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAC3C,GAAG,OAAO,CAAA;gBAEX,MAAM,SAAS,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"notification-subscription.js","sourceRoot":"","sources":["../../../server/service/notification/notification-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAA+E;AAE/E,iDAA0D;AAE1D,iDAA6C;AAGtC,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAgCnC,YAAY,CAAS,OAAuC,EAAyD,QAAkB;QACrI,OAAO,OAAO,CAAC,YAAY,CAAA;IAC7B,CAAC;CACF,CAAA;AAnCY,4DAAwB;AAgCnC;IA/BC,IAAA,2BAAY,EAAC;QACZ,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;YACrC,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,IAAI,CAAA;YAE9B,OAAO,IAAA,mBAAI,EACT,cAAM,CAAC,SAAS,CAAC,cAAc,CAAC,EAChC,IAAA,qBAAM,EAAC,KAAK,EAAE,OAAuC,EAAE,EAAE;gBACvD,wDAAwD;gBACxD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;gBAEtC,MAAM,EACJ,YAAY,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAC3C,GAAG,OAAO,CAAA;gBAEX,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,CAAA;gBAEpC,IAAI,SAAS,EAAE,CAAC;oBACd,IAAI,MAAM,EAAE,SAAS,EAAE,CAAC;wBACtB,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;4BACnC,OAAO,KAAK,CAAA;wBACd,CAAC;oBACH,CAAC;yBAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,EAAE,CAAC;wBAC9D,OAAO,KAAK,CAAA;oBACd,CAAC;gBACH,CAAC;gBAED,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;YACrD,CAAC,CAAC,CACH,CAAA;QACH,CAAC;KACF,CAAC;IACY,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAA2C,mBAAA,IAAA,kBAAG,EAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;;;4CAAsB,2BAAY;4DAErJ;mCAlCU,wBAAwB;IADpC,IAAA,uBAAQ,EAAC,2BAAY,CAAC;GACV,wBAAwB,CAmCpC","sourcesContent":["import { filter, pipe } from 'graphql-yoga'\nimport { Arg, Resolver, FieldResolver, Root, Subscription } from 'type-graphql'\n\nimport { pubsub, ScalarDate } from '@things-factory/shell'\n\nimport { Notification } from './notification'\n\n@Resolver(Notification)\nexport class NotificationSubscription {\n @Subscription({\n subscribe: ({ args, context, info }) => {\n const { subjects = [] } = args\n\n return pipe(\n pubsub.subscribe('notification'),\n filter(async (payload: { notification: Notification }) => {\n /* normally, subscription context doesn't have domain */\n const { domain, user } = context.state\n\n const {\n notification: { subject, domain: pdomain }\n } = payload\n\n const subdomain = pdomain?.subdomain\n\n if (subdomain) {\n if (domain?.subdomain) {\n if (subdomain !== domain.subdomain) {\n return false\n }\n } else if (!user.domains.find(d => d.subdomain === subdomain)) {\n return false\n }\n }\n\n return !subject || subjects.indexOf(subject) !== -1\n })\n )\n }\n })\n notification(@Root() payload: { notification: Notification }, @Arg('subjects', type => [String], { nullable: true }) subjects: string[]): Notification {\n return payload.notification\n }\n}\n"]}
|
|
@@ -10,7 +10,12 @@ const notification_rule_type_1 = require("./notification-rule-type");
|
|
|
10
10
|
let NotificationRuleMutation = class NotificationRuleMutation {
|
|
11
11
|
async createNotificationRule(notificationRule, context) {
|
|
12
12
|
const { domain, user, tx } = context.state;
|
|
13
|
-
const result = await tx.getRepository(notification_rule_1.NotificationRule).save(
|
|
13
|
+
const result = await tx.getRepository(notification_rule_1.NotificationRule).save({
|
|
14
|
+
...notificationRule,
|
|
15
|
+
domain,
|
|
16
|
+
creator: user,
|
|
17
|
+
updater: user
|
|
18
|
+
});
|
|
14
19
|
if (notificationRule.thumbnail) {
|
|
15
20
|
await (0, attachment_base_1.createAttachment)(null, {
|
|
16
21
|
attachment: {
|
|
@@ -28,7 +33,11 @@ let NotificationRuleMutation = class NotificationRuleMutation {
|
|
|
28
33
|
const notificationRule = await repository.findOne({
|
|
29
34
|
where: { domain: { id: domain.id }, id }
|
|
30
35
|
});
|
|
31
|
-
const result = await repository.save(
|
|
36
|
+
const result = await repository.save({
|
|
37
|
+
...notificationRule,
|
|
38
|
+
...patch,
|
|
39
|
+
updater: user
|
|
40
|
+
});
|
|
32
41
|
if (patch.thumbnail) {
|
|
33
42
|
await (0, attachment_base_1.deleteAttachmentsByRef)(null, { refBys: [result.id] }, context);
|
|
34
43
|
await (0, attachment_base_1.createAttachment)(null, {
|
|
@@ -50,7 +59,12 @@ let NotificationRuleMutation = class NotificationRuleMutation {
|
|
|
50
59
|
if (_createRecords.length > 0) {
|
|
51
60
|
for (let i = 0; i < _createRecords.length; i++) {
|
|
52
61
|
const newRecord = _createRecords[i];
|
|
53
|
-
const result = await notificationRuleRepo.save(
|
|
62
|
+
const result = await notificationRuleRepo.save({
|
|
63
|
+
...newRecord,
|
|
64
|
+
domain,
|
|
65
|
+
creator: user,
|
|
66
|
+
updater: user
|
|
67
|
+
});
|
|
54
68
|
if (newRecord.thumbnail) {
|
|
55
69
|
await (0, attachment_base_1.createAttachment)(null, {
|
|
56
70
|
attachment: {
|
|
@@ -60,14 +74,18 @@ let NotificationRuleMutation = class NotificationRuleMutation {
|
|
|
60
74
|
}
|
|
61
75
|
}, context);
|
|
62
76
|
}
|
|
63
|
-
results.push(
|
|
77
|
+
results.push({ ...result, cuFlag: '+' });
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
80
|
if (_updateRecords.length > 0) {
|
|
67
81
|
for (let i = 0; i < _updateRecords.length; i++) {
|
|
68
82
|
const updateRecord = _updateRecords[i];
|
|
69
83
|
const notificationRule = await notificationRuleRepo.findOneBy({ id: updateRecord.id });
|
|
70
|
-
const result = await notificationRuleRepo.save(
|
|
84
|
+
const result = await notificationRuleRepo.save({
|
|
85
|
+
...notificationRule,
|
|
86
|
+
...updateRecord,
|
|
87
|
+
updater: user
|
|
88
|
+
});
|
|
71
89
|
if (updateRecord.thumbnail) {
|
|
72
90
|
await (0, attachment_base_1.deleteAttachmentsByRef)(null, { refBys: [result.id] }, context);
|
|
73
91
|
await (0, attachment_base_1.createAttachment)(null, {
|
|
@@ -78,7 +96,7 @@ let NotificationRuleMutation = class NotificationRuleMutation {
|
|
|
78
96
|
}
|
|
79
97
|
}, context);
|
|
80
98
|
}
|
|
81
|
-
results.push(
|
|
99
|
+
results.push({ ...result, cuFlag: 'M' });
|
|
82
100
|
}
|
|
83
101
|
}
|
|
84
102
|
return results;
|
|
@@ -103,7 +121,7 @@ let NotificationRuleMutation = class NotificationRuleMutation {
|
|
|
103
121
|
await Promise.all(notificationRules.map(async (notificationRule) => {
|
|
104
122
|
const createdNotificationRule = await tx
|
|
105
123
|
.getRepository(notification_rule_1.NotificationRule)
|
|
106
|
-
.save(
|
|
124
|
+
.save({ domain, ...notificationRule });
|
|
107
125
|
}));
|
|
108
126
|
return true;
|
|
109
127
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-rule-mutation.js","sourceRoot":"","sources":["../../../server/service/notification-rule/notification-rule-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,qEAA0F;AAE1F,2DAAsD;AACtD,qEAAqF;AAG9E,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAG7B,AAAN,KAAK,CAAC,sBAAsB,CACD,gBAAqC,EACvD,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,oCAAgB,CAAC,CAAC,IAAI,iCACvD,gBAAgB,KACnB,MAAM,EACN,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,IAAI,IACb,CAAA;QAEF,IAAI,gBAAgB,CAAC,SAAS,EAAE,CAAC;YAC/B,MAAM,IAAA,kCAAgB,EACpB,IAAI,EACJ;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB,CAAC,SAAS;oBAChC,OAAO,EAAE,oCAAgB,CAAC,IAAI;oBAC9B,KAAK,EAAE,MAAM,CAAC,EAAE;iBACjB;aACF,EACD,OAAO,CACR,CAAA;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAIK,AAAN,KAAK,CAAC,sBAAsB,CACf,EAAU,EACP,KAA4B,EACnC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI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AAgB,CAAC;GACd,wBAAwB,CAiMpC","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\n\nimport { NotificationRule } from './notification-rule'\nimport { NewNotificationRule, NotificationRulePatch } from './notification-rule-type'\n\n@Resolver(NotificationRule)\nexport class NotificationRuleMutation {\n @Directive('@transaction')\n @Mutation(returns => NotificationRule, { description: 'To create new NotificationRule' })\n async createNotificationRule(\n @Arg('notificationRule') notificationRule: NewNotificationRule,\n @Ctx() context: ResolverContext\n ): Promise<NotificationRule> {\n const { domain, user, tx } = context.state\n\n const result = await tx.getRepository(NotificationRule).save({\n ...notificationRule,\n domain,\n creator: user,\n updater: user\n })\n\n if (notificationRule.thumbnail) {\n await createAttachment(\n null,\n {\n attachment: {\n file: notificationRule.thumbnail,\n refType: NotificationRule.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => NotificationRule, { description: 'To modify NotificationRule information' })\n async updateNotificationRule(\n @Arg('id') id: string,\n @Arg('patch') patch: NotificationRulePatch,\n @Ctx() context: ResolverContext\n ): Promise<NotificationRule> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(NotificationRule)\n const notificationRule = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...notificationRule,\n ...patch,\n updater: user\n })\n\n if (patch.thumbnail) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.thumbnail,\n refType: NotificationRule.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => [NotificationRule], { description: \"To modify multiple NotificationRules' information\" })\n async updateMultipleNotificationRule(\n @Arg('patches', type => [NotificationRulePatch]) patches: NotificationRulePatch[],\n @Ctx() context: ResolverContext\n ): Promise<NotificationRule[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const notificationRuleRepo = tx.getRepository(NotificationRule)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await notificationRuleRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n if (newRecord.thumbnail) {\n await createAttachment(\n null,\n {\n attachment: {\n file: newRecord.thumbnail,\n refType: NotificationRule.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const notificationRule = await notificationRuleRepo.findOneBy({ id: updateRecord.id })\n\n const result = await notificationRuleRepo.save({\n ...notificationRule,\n ...updateRecord,\n updater: user\n })\n\n if (updateRecord.thumbnail) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: updateRecord.thumbnail,\n refType: NotificationRule.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete NotificationRule' })\n async deleteNotificationRule(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(NotificationRule).delete({ domain: { id: domain.id }, id })\n await deleteAttachmentsByRef(null, { refBys: [id] }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple NotificationRules' })\n async deleteNotificationRules(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(NotificationRule).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n await deleteAttachmentsByRef(null, { refBys: ids }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To import multiple NotificationRules' })\n async importNotificationRules(\n @Arg('notificationRules', type => [NotificationRulePatch]) notificationRules: NotificationRulePatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n notificationRules.map(async (notificationRule: NotificationRulePatch) => {\n const createdNotificationRule: NotificationRule = await tx\n .getRepository(NotificationRule)\n .save({ domain, ...notificationRule })\n })\n )\n\n return true\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notification-rule-mutation.js","sourceRoot":"","sources":["../../../server/service/notification-rule/notification-rule-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,qEAA0F;AAE1F,2DAAsD;AACtD,qEAAqF;AAG9E,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAG7B,AAAN,KAAK,CAAC,sBAAsB,CACD,gBAAqC,EACvD,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,oCAAgB,CAAC,CAAC,IAAI,CAAC;YAC3D,GAAG,gBAAgB;YACnB,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QAEF,IAAI,gBAAgB,CAAC,SAAS,EAAE,CAAC;YAC/B,MAAM,IAAA,kCAAgB,EACpB,IAAI,EACJ;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB,CAAC,SAAS;oBAChC,OAAO,EAAE,oCAAgB,CAAC,IAAI;oBAC9B,KAAK,EAAE,MAAM,CAAC,EAAE;iBACjB;aACF,EACD,OAAO,CACR,CAAA;QACH,CAAC;QAED,OAAO,MAAM,C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,EAAE,EAAE,WAAW,EAAE,sCAAsC,EAAE,CAAC;IAEnF,mBAAA,IAAA,kBAAG,EAAC,mBAAmB,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,8CAAqB,CAAC,CAAC,CAAA;IACzD,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;uEAaP;mCAhMU,wBAAwB;IADpC,IAAA,uBAAQ,EAAC,oCAAgB,CAAC;GACd,wBAAwB,CAiMpC","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\n\nimport { NotificationRule } from './notification-rule'\nimport { NewNotificationRule, NotificationRulePatch } from './notification-rule-type'\n\n@Resolver(NotificationRule)\nexport class NotificationRuleMutation {\n @Directive('@transaction')\n @Mutation(returns => NotificationRule, { description: 'To create new NotificationRule' })\n async createNotificationRule(\n @Arg('notificationRule') notificationRule: NewNotificationRule,\n @Ctx() context: ResolverContext\n ): Promise<NotificationRule> {\n const { domain, user, tx } = context.state\n\n const result = await tx.getRepository(NotificationRule).save({\n ...notificationRule,\n domain,\n creator: user,\n updater: user\n })\n\n if (notificationRule.thumbnail) {\n await createAttachment(\n null,\n {\n attachment: {\n file: notificationRule.thumbnail,\n refType: NotificationRule.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => NotificationRule, { description: 'To modify NotificationRule information' })\n async updateNotificationRule(\n @Arg('id') id: string,\n @Arg('patch') patch: NotificationRulePatch,\n @Ctx() context: ResolverContext\n ): Promise<NotificationRule> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(NotificationRule)\n const notificationRule = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...notificationRule,\n ...patch,\n updater: user\n })\n\n if (patch.thumbnail) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.thumbnail,\n refType: NotificationRule.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => [NotificationRule], { description: \"To modify multiple NotificationRules' information\" })\n async updateMultipleNotificationRule(\n @Arg('patches', type => [NotificationRulePatch]) patches: NotificationRulePatch[],\n @Ctx() context: ResolverContext\n ): Promise<NotificationRule[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const notificationRuleRepo = tx.getRepository(NotificationRule)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await notificationRuleRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n if (newRecord.thumbnail) {\n await createAttachment(\n null,\n {\n attachment: {\n file: newRecord.thumbnail,\n refType: NotificationRule.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const notificationRule = await notificationRuleRepo.findOneBy({ id: updateRecord.id })\n\n const result = await notificationRuleRepo.save({\n ...notificationRule,\n ...updateRecord,\n updater: user\n })\n\n if (updateRecord.thumbnail) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: updateRecord.thumbnail,\n refType: NotificationRule.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete NotificationRule' })\n async deleteNotificationRule(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(NotificationRule).delete({ domain: { id: domain.id }, id })\n await deleteAttachmentsByRef(null, { refBys: [id] }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple NotificationRules' })\n async deleteNotificationRules(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(NotificationRule).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n await deleteAttachmentsByRef(null, { refBys: ids }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To import multiple NotificationRules' })\n async importNotificationRules(\n @Arg('notificationRules', type => [NotificationRulePatch]) notificationRules: NotificationRulePatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n notificationRules.map(async (notificationRule: NotificationRulePatch) => {\n const createdNotificationRule: NotificationRule = await tx\n .getRepository(NotificationRule)\n .save({ domain, ...notificationRule })\n })\n )\n\n return true\n }\n}\n"]}
|