@things-factory/notification 10.1.104 → 10.1.106
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/tsconfig.tsbuildinfo +1 -1
- package/dist-server/service/notification-rule/notification-rule-mutation.js +6 -0
- package/dist-server/service/notification-rule/notification-rule-mutation.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/tests/open-doors.test.ts +54 -0
- package/things-factory.config.js +2 -2
|
@@ -134,6 +134,7 @@ let NotificationRuleMutation = class NotificationRuleMutation {
|
|
|
134
134
|
exports.NotificationRuleMutation = NotificationRuleMutation;
|
|
135
135
|
tslib_1.__decorate([
|
|
136
136
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
137
|
+
(0, type_graphql_1.Directive)('@privilege(category: "notification-rule", privilege: "mutation", domainOwnerGranted: true)'),
|
|
137
138
|
(0, type_graphql_1.Mutation)(returns => notification_rule_1.NotificationRule, { description: 'To create new NotificationRule' }),
|
|
138
139
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('notificationRule')),
|
|
139
140
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -143,6 +144,7 @@ tslib_1.__decorate([
|
|
|
143
144
|
], NotificationRuleMutation.prototype, "createNotificationRule", null);
|
|
144
145
|
tslib_1.__decorate([
|
|
145
146
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
147
|
+
(0, type_graphql_1.Directive)('@privilege(category: "notification-rule", privilege: "mutation", domainOwnerGranted: true)'),
|
|
146
148
|
(0, type_graphql_1.Mutation)(returns => notification_rule_1.NotificationRule, { description: 'To modify NotificationRule information' }),
|
|
147
149
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
148
150
|
tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
|
|
@@ -153,6 +155,7 @@ tslib_1.__decorate([
|
|
|
153
155
|
], NotificationRuleMutation.prototype, "updateNotificationRule", null);
|
|
154
156
|
tslib_1.__decorate([
|
|
155
157
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
158
|
+
(0, type_graphql_1.Directive)('@privilege(category: "notification-rule", privilege: "mutation", domainOwnerGranted: true)'),
|
|
156
159
|
(0, type_graphql_1.Mutation)(returns => [notification_rule_1.NotificationRule], { description: "To modify multiple NotificationRules' information" }),
|
|
157
160
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [notification_rule_type_1.NotificationRulePatch])),
|
|
158
161
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -162,6 +165,7 @@ tslib_1.__decorate([
|
|
|
162
165
|
], NotificationRuleMutation.prototype, "updateMultipleNotificationRule", null);
|
|
163
166
|
tslib_1.__decorate([
|
|
164
167
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
168
|
+
(0, type_graphql_1.Directive)('@privilege(category: "notification-rule", privilege: "mutation", domainOwnerGranted: true)'),
|
|
165
169
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete NotificationRule' }),
|
|
166
170
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
167
171
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -171,6 +175,7 @@ tslib_1.__decorate([
|
|
|
171
175
|
], NotificationRuleMutation.prototype, "deleteNotificationRule", null);
|
|
172
176
|
tslib_1.__decorate([
|
|
173
177
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
178
|
+
(0, type_graphql_1.Directive)('@privilege(category: "notification-rule", privilege: "mutation", domainOwnerGranted: true)'),
|
|
174
179
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete multiple NotificationRules' }),
|
|
175
180
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
|
|
176
181
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -180,6 +185,7 @@ tslib_1.__decorate([
|
|
|
180
185
|
], NotificationRuleMutation.prototype, "deleteNotificationRules", null);
|
|
181
186
|
tslib_1.__decorate([
|
|
182
187
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
188
|
+
(0, type_graphql_1.Directive)('@privilege(category: "notification-rule", privilege: "mutation", domainOwnerGranted: true)'),
|
|
183
189
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To import multiple NotificationRules' }),
|
|
184
190
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('notificationRules', type => [notification_rule_type_1.NotificationRulePatch])),
|
|
185
191
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -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,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,CAAA;IACf,CAAC;IAIK,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C,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;uEAYP;AAIK;IAFL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,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;mCAtMU,wBAAwB;IADpC,IAAA,uBAAQ,EAAC,oCAAgB,CAAC;GACd,wBAAwB,CAuMpC","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.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!notificationRule) {\n throw new Error(`failed to find notificationRule to update: ${updateRecord.id}`)\n }\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;IAI7B,AAAN,KAAK,CAAC,sBAAsB,CACD,gBAAqC,EACvD,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,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ACd,wBAAwB,CA6MpC","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 @Directive('@privilege(category: \"notification-rule\", privilege: \"mutation\", domainOwnerGranted: true)')\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 @Directive('@privilege(category: \"notification-rule\", privilege: \"mutation\", domainOwnerGranted: true)')\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 @Directive('@privilege(category: \"notification-rule\", privilege: \"mutation\", domainOwnerGranted: true)')\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.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!notificationRule) {\n throw new Error(`failed to find notificationRule to update: ${updateRecord.id}`)\n }\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 @Directive('@privilege(category: \"notification-rule\", privilege: \"mutation\", domainOwnerGranted: true)')\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 @Directive('@privilege(category: \"notification-rule\", privilege: \"mutation\", domainOwnerGranted: true)')\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 @Directive('@privilege(category: \"notification-rule\", privilege: \"mutation\", domainOwnerGranted: true)')\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"]}
|