@things-factory/code-base 10.1.79 → 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.
@@ -4,14 +4,28 @@ exports.CommonCodeMutation = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const type_graphql_1 = require("type-graphql");
6
6
  const typeorm_1 = require("typeorm");
7
- const shell_1 = require("@things-factory/shell");
8
7
  const common_code_detail_1 = require("../common-code-detail/common-code-detail");
9
8
  const common_code_1 = require("./common-code");
10
9
  const common_code_type_1 = require("./common-code-type");
10
+ /*
11
+ * The details a code group is given, looked up inside the caller's domain. By id alone, a group of
12
+ * one domain could take over another domain's details.
13
+ */
14
+ async function detailsInDomain(tx, domain, ids) {
15
+ const unique = [...new Set(ids)];
16
+ if (!unique.length)
17
+ return [];
18
+ const details = await tx.getRepository(common_code_detail_1.CommonCodeDetail).findBy({ domain: { id: domain.id }, id: (0, typeorm_1.In)(unique) });
19
+ const missing = unique.filter(id => !details.some(detail => detail.id === id));
20
+ if (missing.length) {
21
+ throw new Error(`common code detail not found in this domain: ${missing.join(', ')}`);
22
+ }
23
+ return details;
24
+ }
11
25
  let CommonCodeMutation = class CommonCodeMutation {
12
26
  async createCommonCode(commonCode, context) {
13
27
  const { domain, user, tx } = context.state;
14
- const details = await (0, shell_1.getRepository)(common_code_detail_1.CommonCodeDetail).findByIds(commonCode.details || []);
28
+ const details = await detailsInDomain(tx, domain, commonCode.details || []);
15
29
  return await tx.getRepository(common_code_1.CommonCode).save({
16
30
  ...commonCode,
17
31
  details,
@@ -27,6 +41,9 @@ let CommonCodeMutation = class CommonCodeMutation {
27
41
  where: { domain: { id: domain.id }, name },
28
42
  relations: ['details']
29
43
  });
44
+ if (!commonCode) {
45
+ throw new Error(`common code not found in this domain: ${name}`);
46
+ }
30
47
  const detailIds = commonCode.details.map(detail => detail.id);
31
48
  if (patch.details && patch.details.length) {
32
49
  patch.details.forEach((detailId) => {
@@ -38,7 +55,7 @@ let CommonCodeMutation = class CommonCodeMutation {
38
55
  return await repository.save({
39
56
  ...commonCode,
40
57
  ...patch,
41
- details: await (0, shell_1.getRepository)(common_code_detail_1.CommonCodeDetail).findByIds(detailIds),
58
+ details: await detailsInDomain(tx, domain, detailIds),
42
59
  updater: user
43
60
  });
44
61
  }
@@ -63,7 +80,10 @@ let CommonCodeMutation = class CommonCodeMutation {
63
80
  if (_updateRecords.length > 0) {
64
81
  for (let i = 0; i < _updateRecords.length; i++) {
65
82
  const newRecord = _updateRecords[i];
66
- const commonCode = await commonCodeRepo.findOneBy({ id: newRecord.id });
83
+ const commonCode = await commonCodeRepo.findOne({ where: { domain: { id: domain.id }, id: newRecord.id } });
84
+ if (!commonCode) {
85
+ throw new Error(`common code not found in this domain: ${newRecord.id}`);
86
+ }
67
87
  const result = await commonCodeRepo.save({
68
88
  ...commonCode,
69
89
  ...newRecord,
@@ -100,6 +120,7 @@ let CommonCodeMutation = class CommonCodeMutation {
100
120
  exports.CommonCodeMutation = CommonCodeMutation;
101
121
  tslib_1.__decorate([
102
122
  (0, type_graphql_1.Directive)('@transaction'),
123
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
103
124
  (0, type_graphql_1.Mutation)(returns => common_code_1.CommonCode, { description: 'To create new CommonCode' }),
104
125
  tslib_1.__param(0, (0, type_graphql_1.Arg)('commonCode')),
105
126
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -109,6 +130,7 @@ tslib_1.__decorate([
109
130
  ], CommonCodeMutation.prototype, "createCommonCode", null);
110
131
  tslib_1.__decorate([
111
132
  (0, type_graphql_1.Directive)('@transaction'),
133
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
112
134
  (0, type_graphql_1.Mutation)(returns => common_code_1.CommonCode, { description: 'To modify CommonCode information' }),
113
135
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
114
136
  tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
@@ -119,6 +141,7 @@ tslib_1.__decorate([
119
141
  ], CommonCodeMutation.prototype, "updateCommonCode", null);
120
142
  tslib_1.__decorate([
121
143
  (0, type_graphql_1.Directive)('@transaction'),
144
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
122
145
  (0, type_graphql_1.Mutation)(returns => [common_code_1.CommonCode], { description: "To modify multiple CommonCodes' information" }),
123
146
  tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [common_code_type_1.CommonCodePatch])),
124
147
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -128,6 +151,7 @@ tslib_1.__decorate([
128
151
  ], CommonCodeMutation.prototype, "updateMultipleCommonCode", null);
129
152
  tslib_1.__decorate([
130
153
  (0, type_graphql_1.Directive)('@transaction'),
154
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
131
155
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete CommonCode' }),
132
156
  tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
133
157
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -137,6 +161,7 @@ tslib_1.__decorate([
137
161
  ], CommonCodeMutation.prototype, "deleteCommonCode", null);
138
162
  tslib_1.__decorate([
139
163
  (0, type_graphql_1.Directive)('@transaction'),
164
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
140
165
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete multiple CommonCodes' }),
141
166
  tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
142
167
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -146,6 +171,7 @@ tslib_1.__decorate([
146
171
  ], CommonCodeMutation.prototype, "deleteCommonCodes", null);
147
172
  tslib_1.__decorate([
148
173
  (0, type_graphql_1.Directive)('@transaction'),
174
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
149
175
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To import multiple CommonCodes' }),
150
176
  tslib_1.__param(0, (0, type_graphql_1.Arg)('commonCodes', type => [common_code_type_1.CommonCodePatch])),
151
177
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -1 +1 @@
1
- {"version":3,"file":"common-code-mutation.js","sourceRoot":"","sources":["../../../server/service/common-code/common-code-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AAErD,iFAA2E;AAC3E,+CAA0C;AAC1C,yDAAmE;AAG5D,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAGvB,AAAN,KAAK,CAAC,gBAAgB,CACD,UAAyB,EACrC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,OAAO,GAAG,MAAM,IAAA,qBAAa,EAAC,qCAAgB,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAAC,CAAA;QAEzF,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,wBAAU,CAAC,CAAC,IAAI,CAAC;YAC7C,GAAG,UAAU;YACb,OAAO;YACP,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC;IAIK,AAAN,KAAK,CAAC,gBAAgB,CACP,IAAY,EACX,KAAsB,EAC7B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,wBAAU,CAAC,CAAA;QAC/C,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC1C,KAAK,EAAE,EAAE,M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AAA,kBAAG,GAAE,CAAA;;;;2DAUP;AAIK;IAFL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IAE7E,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,kCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAaP;6BA5IU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,wBAAU,CAAC;GACR,kBAAkB,CA6I9B","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { CommonCodeDetail } from '../common-code-detail/common-code-detail'\nimport { CommonCode } from './common-code'\nimport { CommonCodePatch, NewCommonCode } from './common-code-type'\n\n@Resolver(CommonCode)\nexport class CommonCodeMutation {\n @Directive('@transaction')\n @Mutation(returns => CommonCode, { description: 'To create new CommonCode' })\n async createCommonCode(\n @Arg('commonCode') commonCode: NewCommonCode,\n @Ctx() context: ResolverContext\n ): Promise<CommonCode> {\n const { domain, user, tx } = context.state\n\n const details = await getRepository(CommonCodeDetail).findByIds(commonCode.details || [])\n\n return await tx.getRepository(CommonCode).save({\n ...commonCode,\n details,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => CommonCode, { description: 'To modify CommonCode information' })\n async updateCommonCode(\n @Arg('name') name: string,\n @Arg('patch') patch: CommonCodePatch,\n @Ctx() context: ResolverContext\n ): Promise<CommonCode> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(CommonCode)\n const commonCode = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['details']\n })\n\n const detailIds = commonCode.details.map(detail => detail.id)\n if (patch.details && patch.details.length) {\n patch.details.forEach((detailId: string) => {\n if (!detailIds.includes(detailId)) {\n detailIds.push(detailId)\n }\n })\n }\n\n return await repository.save({\n ...commonCode,\n ...patch,\n details: await getRepository(CommonCodeDetail).findByIds(detailIds),\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => [CommonCode], { description: \"To modify multiple CommonCodes' information\" })\n async updateMultipleCommonCode(\n @Arg('patches', type => [CommonCodePatch]) patches: CommonCodePatch[],\n @Ctx() context: ResolverContext\n ): Promise<CommonCode[]> {\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 commonCodeRepo = tx.getRepository(CommonCode)\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 commonCodeRepo.save({\n ...(newRecord as any),\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 newRecord = _updateRecords[i]\n const commonCode = await commonCodeRepo.findOneBy({ id: newRecord.id })\n\n const result = await commonCodeRepo.save({\n ...commonCode,\n ...(newRecord as any),\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 CommonCode' })\n async deleteCommonCode(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(CommonCode).delete({ domain: { id: domain.id }, id })\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple CommonCodes' })\n async deleteCommonCodes(\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(CommonCode).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To import multiple CommonCodes' })\n async importCommonCodes(\n @Arg('commonCodes', type => [CommonCodePatch]) commonCodes: CommonCodePatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n commonCodes.map(async (commonCode: CommonCodePatch) => {\n const createdCommonCode: CommonCode = await tx\n .getRepository(CommonCode)\n .save({ domain, ...(commonCode as any) })\n })\n )\n\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"common-code-mutation.js","sourceRoot":"","sources":["../../../server/service/common-code/common-code-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA2C;AAI3C,iFAA2E;AAC3E,+CAA0C;AAC1C,yDAAmE;AAEnE;;;GAGG;AACH,KAAK,UAAU,eAAe,CAAC,EAAiB,EAAE,MAAc,EAAE,GAAa;IAC7E,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IAChC,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,EAAE,CAAA;IAE7B,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,qCAAgB,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,IAAA,YAAE,EAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC9G,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;IAC9E,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,gDAAgD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC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IAE7E,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAUP;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,sFAAsF,CAAC;IACjG,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IAE7E,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,kCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAaP;6BAxJU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,wBAAU,CAAC;GACR,kBAAkB,CAyJ9B","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { EntityManager, In } from 'typeorm'\n\nimport { Domain } from '@things-factory/shell'\n\nimport { CommonCodeDetail } from '../common-code-detail/common-code-detail'\nimport { CommonCode } from './common-code'\nimport { CommonCodePatch, NewCommonCode } from './common-code-type'\n\n/*\n * The details a code group is given, looked up inside the caller's domain. By id alone, a group of\n * one domain could take over another domain's details.\n */\nasync function detailsInDomain(tx: EntityManager, domain: Domain, ids: string[]): Promise<CommonCodeDetail[]> {\n const unique = [...new Set(ids)]\n if (!unique.length) return []\n\n const details = await tx.getRepository(CommonCodeDetail).findBy({ domain: { id: domain.id }, id: In(unique) })\n const missing = unique.filter(id => !details.some(detail => detail.id === id))\n if (missing.length) {\n throw new Error(`common code detail not found in this domain: ${missing.join(', ')}`)\n }\n return details\n}\n\n@Resolver(CommonCode)\nexport class CommonCodeMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => CommonCode, { description: 'To create new CommonCode' })\n async createCommonCode(\n @Arg('commonCode') commonCode: NewCommonCode,\n @Ctx() context: ResolverContext\n ): Promise<CommonCode> {\n const { domain, user, tx } = context.state\n\n const details = await detailsInDomain(tx, domain, commonCode.details || [])\n\n return await tx.getRepository(CommonCode).save({\n ...commonCode,\n details,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => CommonCode, { description: 'To modify CommonCode information' })\n async updateCommonCode(\n @Arg('name') name: string,\n @Arg('patch') patch: CommonCodePatch,\n @Ctx() context: ResolverContext\n ): Promise<CommonCode> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(CommonCode)\n const commonCode = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['details']\n })\n if (!commonCode) {\n throw new Error(`common code not found in this domain: ${name}`)\n }\n\n const detailIds = commonCode.details.map(detail => detail.id)\n if (patch.details && patch.details.length) {\n patch.details.forEach((detailId: string) => {\n if (!detailIds.includes(detailId)) {\n detailIds.push(detailId)\n }\n })\n }\n\n return await repository.save({\n ...commonCode,\n ...patch,\n details: await detailsInDomain(tx, domain, detailIds),\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => [CommonCode], { description: \"To modify multiple CommonCodes' information\" })\n async updateMultipleCommonCode(\n @Arg('patches', type => [CommonCodePatch]) patches: CommonCodePatch[],\n @Ctx() context: ResolverContext\n ): Promise<CommonCode[]> {\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 commonCodeRepo = tx.getRepository(CommonCode)\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 commonCodeRepo.save({\n ...(newRecord as any),\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 newRecord = _updateRecords[i]\n const commonCode = await commonCodeRepo.findOne({ where: { domain: { id: domain.id }, id: newRecord.id } })\n if (!commonCode) {\n throw new Error(`common code not found in this domain: ${newRecord.id}`)\n }\n\n const result = await commonCodeRepo.save({\n ...commonCode,\n ...(newRecord as any),\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete CommonCode' })\n async deleteCommonCode(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(CommonCode).delete({ domain: { id: domain.id }, id })\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete multiple CommonCodes' })\n async deleteCommonCodes(\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(CommonCode).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To import multiple CommonCodes' })\n async importCommonCodes(\n @Arg('commonCodes', type => [CommonCodePatch]) commonCodes: CommonCodePatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n commonCodes.map(async (commonCode: CommonCodePatch) => {\n const createdCommonCode: CommonCode = await tx\n .getRepository(CommonCode)\n .save({ domain, ...(commonCode as any) })\n })\n )\n\n return true\n }\n}\n"]}
@@ -7,11 +7,22 @@ const typeorm_1 = require("typeorm");
7
7
  const common_code_1 = require("../common-code/common-code");
8
8
  const common_code_detail_1 = require("./common-code-detail");
9
9
  const common_code_detail_type_1 = require("./common-code-detail-type");
10
+ /*
11
+ * The code group a detail is put under, looked up inside the caller's domain. By id alone, a detail
12
+ * of one domain could be put under another domain's group.
13
+ */
14
+ async function commonCodeInDomain(tx, domain, id) {
15
+ const commonCode = await tx.getRepository(common_code_1.CommonCode).findOne({ where: { domain: { id: domain.id }, id } });
16
+ if (!commonCode) {
17
+ throw new Error(`common code not found in this domain: ${id}`);
18
+ }
19
+ return commonCode;
20
+ }
10
21
  let CommonCodeDetailMutation = class CommonCodeDetailMutation {
11
22
  async createCommonCodeDetail(commonCodeDetail, context) {
12
23
  const { domain, user, tx } = context.state;
13
24
  if (commonCodeDetail && commonCodeDetail.commonCode.id) {
14
- commonCodeDetail.commonCode = await tx.getRepository(common_code_1.CommonCode).findOneBy({ id: commonCodeDetail.commonCode.id });
25
+ commonCodeDetail.commonCode = await commonCodeInDomain(tx, domain, commonCodeDetail.commonCode.id);
15
26
  }
16
27
  return await tx.getRepository(common_code_detail_1.CommonCodeDetail).save({
17
28
  ...commonCodeDetail,
@@ -26,8 +37,11 @@ let CommonCodeDetailMutation = class CommonCodeDetailMutation {
26
37
  const commonCodeDetail = await repository.findOne({
27
38
  where: { domain: { id: domain.id }, id }
28
39
  });
40
+ if (!commonCodeDetail) {
41
+ throw new Error(`common code detail not found in this domain: ${id}`);
42
+ }
29
43
  if (patch.commonCode && patch.commonCode.id) {
30
- patch.commonCode = await tx.getRepository(common_code_1.CommonCode).findOneBy({ id: patch.commonCode.id });
44
+ patch.commonCode = await commonCodeInDomain(tx, domain, patch.commonCode.id);
31
45
  }
32
46
  return await repository.save({
33
47
  ...commonCodeDetail,
@@ -40,7 +54,6 @@ let CommonCodeDetailMutation = class CommonCodeDetailMutation {
40
54
  let results = [];
41
55
  const _createRecords = patches.filter((patch) => patch.cuFlag.toUpperCase() === '+');
42
56
  const _updateRecords = patches.filter((patch) => patch.cuFlag.toUpperCase() === 'M');
43
- const commonCodeRepo = tx.getRepository(common_code_1.CommonCode);
44
57
  const commonCodeDetailRepo = tx.getRepository(common_code_detail_1.CommonCodeDetail);
45
58
  if (_createRecords.length > 0) {
46
59
  for (let i = 0; i < _createRecords.length; i++) {
@@ -50,7 +63,7 @@ let CommonCodeDetailMutation = class CommonCodeDetailMutation {
50
63
  newRecord.description = newRecord.labels[user.locale] || '';
51
64
  }
52
65
  if (newRecord.commonCode && newRecord.commonCode.id) {
53
- newRecord.commonCode = await commonCodeRepo.findOneBy({ id: newRecord.commonCode.id });
66
+ newRecord.commonCode = await commonCodeInDomain(tx, domain, newRecord.commonCode.id);
54
67
  }
55
68
  const result = await commonCodeDetailRepo.save({
56
69
  ...newRecord,
@@ -64,13 +77,18 @@ let CommonCodeDetailMutation = class CommonCodeDetailMutation {
64
77
  if (_updateRecords.length > 0) {
65
78
  for (let i = 0; i < _updateRecords.length; i++) {
66
79
  const newRecord = _updateRecords[i];
67
- const commonCodeDetail = await commonCodeDetailRepo.findOneBy({ id: newRecord.id });
80
+ const commonCodeDetail = await commonCodeDetailRepo.findOne({
81
+ where: { domain: { id: domain.id }, id: newRecord.id }
82
+ });
83
+ if (!commonCodeDetail) {
84
+ throw new Error(`common code detail not found in this domain: ${newRecord.id}`);
85
+ }
68
86
  // 기존 description 필드 - 현재 locale로 기본값 넣어줌
69
87
  if (!commonCodeDetail.description) {
70
88
  newRecord.description = newRecord.labels[user.locale] || '';
71
89
  }
72
90
  if (newRecord.commonCode && newRecord.commonCode.id) {
73
- newRecord.commonCode = await commonCodeRepo.findOneBy({ id: newRecord.commonCode.id });
91
+ newRecord.commonCode = await commonCodeInDomain(tx, domain, newRecord.commonCode.id);
74
92
  }
75
93
  const result = await commonCodeDetailRepo.save({
76
94
  ...commonCodeDetail,
@@ -108,6 +126,7 @@ let CommonCodeDetailMutation = class CommonCodeDetailMutation {
108
126
  exports.CommonCodeDetailMutation = CommonCodeDetailMutation;
109
127
  tslib_1.__decorate([
110
128
  (0, type_graphql_1.Directive)('@transaction'),
129
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
111
130
  (0, type_graphql_1.Mutation)(returns => common_code_detail_1.CommonCodeDetail, { description: 'To create new CommonCodeDetail' }),
112
131
  tslib_1.__param(0, (0, type_graphql_1.Arg)('commonCodeDetail')),
113
132
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -117,6 +136,7 @@ tslib_1.__decorate([
117
136
  ], CommonCodeDetailMutation.prototype, "createCommonCodeDetail", null);
118
137
  tslib_1.__decorate([
119
138
  (0, type_graphql_1.Directive)('@transaction'),
139
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
120
140
  (0, type_graphql_1.Mutation)(returns => common_code_detail_1.CommonCodeDetail, { description: 'To modify CommonCodeDetail information' }),
121
141
  tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
122
142
  tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
@@ -127,6 +147,7 @@ tslib_1.__decorate([
127
147
  ], CommonCodeDetailMutation.prototype, "updateCommonCodeDetail", null);
128
148
  tslib_1.__decorate([
129
149
  (0, type_graphql_1.Directive)('@transaction'),
150
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
130
151
  (0, type_graphql_1.Mutation)(returns => [common_code_detail_1.CommonCodeDetail], { description: "To modify multiple CommonCodeDetails' information" }),
131
152
  tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [common_code_detail_type_1.CommonCodeDetailPatch])),
132
153
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -136,6 +157,7 @@ tslib_1.__decorate([
136
157
  ], CommonCodeDetailMutation.prototype, "updateMultipleCommonCodeDetail", null);
137
158
  tslib_1.__decorate([
138
159
  (0, type_graphql_1.Directive)('@transaction'),
160
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
139
161
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete CommonCodeDetail' }),
140
162
  tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
141
163
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -145,6 +167,7 @@ tslib_1.__decorate([
145
167
  ], CommonCodeDetailMutation.prototype, "deleteCommonCodeDetail", null);
146
168
  tslib_1.__decorate([
147
169
  (0, type_graphql_1.Directive)('@transaction'),
170
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
148
171
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete multiple CommonCodeDetails' }),
149
172
  tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
150
173
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -154,6 +177,7 @@ tslib_1.__decorate([
154
177
  ], CommonCodeDetailMutation.prototype, "deleteCommonCodeDetails", null);
155
178
  tslib_1.__decorate([
156
179
  (0, type_graphql_1.Directive)('@transaction'),
180
+ (0, type_graphql_1.Directive)('@privilege(category: "common-code", privilege: "mutation", domainOwnerGranted: true)'),
157
181
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To import multiple CommonCodeDetails' }),
158
182
  tslib_1.__param(0, (0, type_graphql_1.Arg)('commonCodeDetails', type => [common_code_detail_type_1.CommonCodeDetailPatch])),
159
183
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -1 +1 @@
1
- {"version":3,"file":"common-code-detail-mutation.js","sourceRoot":"","sources":["../../../server/service/common-code-detail/common-code-detail-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,4DAAuD;AACvD,6DAAuD;AACvD,uEAAsF;AAG/E,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAG7B,AA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AC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,sCAAsC,EAAE,CAAC;IAEnF,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;uEAUP;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,+CAAqB,CAAC,CAAC,CAAA;IACzD,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;uEAaP;mCAzJU,wBAAwB;IADpC,IAAA,uBAAQ,EAAC,qCAAgB,CAAC;GACd,wBAAwB,CA0JpC","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { CommonCode } from '../common-code/common-code'\nimport { CommonCodeDetail } from './common-code-detail'\nimport { CommonCodeDetailPatch, NewCommonCodeDetail } from './common-code-detail-type'\n\n@Resolver(CommonCodeDetail)\nexport class CommonCodeDetailMutation {\n @Directive('@transaction')\n @Mutation(returns => CommonCodeDetail, { description: 'To create new CommonCodeDetail' })\n async createCommonCodeDetail(\n @Arg('commonCodeDetail') commonCodeDetail: NewCommonCodeDetail,\n @Ctx() context: ResolverContext\n ): Promise<CommonCodeDetail> {\n const { domain, user, tx } = context.state\n\n if (commonCodeDetail && commonCodeDetail.commonCode.id) {\n commonCodeDetail.commonCode = await tx.getRepository(CommonCode).findOneBy({ id: commonCodeDetail.commonCode.id })\n }\n\n return await tx.getRepository(CommonCodeDetail).save({\n ...commonCodeDetail,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => CommonCodeDetail, { description: 'To modify CommonCodeDetail information' })\n async updateCommonCodeDetail(\n @Arg('id') id: string,\n @Arg('patch') patch: CommonCodeDetailPatch,\n @Ctx() context: ResolverContext\n ): Promise<CommonCodeDetail> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(CommonCodeDetail)\n const commonCodeDetail = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n if (patch.commonCode && patch.commonCode.id) {\n patch.commonCode = await tx.getRepository(CommonCode).findOneBy({ id: patch.commonCode.id })\n }\n\n return await repository.save({\n ...commonCodeDetail,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => [CommonCodeDetail], { description: \"To modify multiple CommonCodeDetails' information\" })\n async updateMultipleCommonCodeDetail(\n @Arg('patches', type => [CommonCodeDetailPatch]) patches: CommonCodeDetailPatch[],\n @Ctx() context: ResolverContext\n ): Promise<CommonCodeDetail[]> {\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 commonCodeRepo = tx.getRepository(CommonCode)\n const commonCodeDetailRepo = tx.getRepository(CommonCodeDetail)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n // 기존 description 필드 - 현재 locale로 기본값 넣어줌\n if (!newRecord.description) {\n newRecord.description = newRecord.labels[user.locale] || ''\n }\n\n if (newRecord.commonCode && newRecord.commonCode.id) {\n newRecord.commonCode = await commonCodeRepo.findOneBy({ id: newRecord.commonCode.id })\n }\n\n const result = await commonCodeDetailRepo.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 newRecord = _updateRecords[i]\n const commonCodeDetail = await commonCodeDetailRepo.findOneBy({ id: newRecord.id })\n\n // 기존 description 필드 - 현재 locale로 기본값 넣어줌\n if (!commonCodeDetail.description) {\n newRecord.description = newRecord.labels[user.locale] || ''\n }\n\n if (newRecord.commonCode && newRecord.commonCode.id) {\n newRecord.commonCode = await commonCodeRepo.findOneBy({ id: newRecord.commonCode.id })\n }\n\n const result = await commonCodeDetailRepo.save({\n ...commonCodeDetail,\n ...newRecord,\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 CommonCodeDetail' })\n async deleteCommonCodeDetail(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(CommonCodeDetail).delete({ domain: { id: domain.id }, id })\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple CommonCodeDetails' })\n async deleteCommonCodeDetails(\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(CommonCodeDetail).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To import multiple CommonCodeDetails' })\n async importCommonCodeDetails(\n @Arg('commonCodeDetails', type => [CommonCodeDetailPatch]) commonCodeDetails: CommonCodeDetailPatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n commonCodeDetails.map(async (commonCodeDetail: CommonCodeDetailPatch) => {\n const createdCommonCodeDetail: CommonCodeDetail = await tx\n .getRepository(CommonCodeDetail)\n .save({ domain, ...commonCodeDetail })\n })\n )\n\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"common-code-detail-mutation.js","sourceRoot":"","sources":["../../../server/service/common-code-detail/common-code-detail-mutation.ts"],"names":[],"mappings":";;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AAS,EAAC,sFAAsF,CAAC;IACjG,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,+CAAqB,CAAC,CAAC,CAAA;IACzD,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;uEAaP;mCAtKU,wBAAwB;IADpC,IAAA,uBAAQ,EAAC,qCAAgB,CAAC;GACd,wBAAwB,CAuKpC","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { EntityManager, In } from 'typeorm'\n\nimport { Domain } from '@things-factory/shell'\n\nimport { CommonCode } from '../common-code/common-code'\nimport { CommonCodeDetail } from './common-code-detail'\nimport { CommonCodeDetailPatch, NewCommonCodeDetail } from './common-code-detail-type'\n\n/*\n * The code group a detail is put under, looked up inside the caller's domain. By id alone, a detail\n * of one domain could be put under another domain's group.\n */\nasync function commonCodeInDomain(tx: EntityManager, domain: Domain, id: string): Promise<CommonCode> {\n const commonCode = await tx.getRepository(CommonCode).findOne({ where: { domain: { id: domain.id }, id } })\n if (!commonCode) {\n throw new Error(`common code not found in this domain: ${id}`)\n }\n return commonCode\n}\n\n@Resolver(CommonCodeDetail)\nexport class CommonCodeDetailMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => CommonCodeDetail, { description: 'To create new CommonCodeDetail' })\n async createCommonCodeDetail(\n @Arg('commonCodeDetail') commonCodeDetail: NewCommonCodeDetail,\n @Ctx() context: ResolverContext\n ): Promise<CommonCodeDetail> {\n const { domain, user, tx } = context.state\n\n if (commonCodeDetail && commonCodeDetail.commonCode.id) {\n commonCodeDetail.commonCode = await commonCodeInDomain(tx, domain, commonCodeDetail.commonCode.id)\n }\n\n return await tx.getRepository(CommonCodeDetail).save({\n ...commonCodeDetail,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => CommonCodeDetail, { description: 'To modify CommonCodeDetail information' })\n async updateCommonCodeDetail(\n @Arg('id') id: string,\n @Arg('patch') patch: CommonCodeDetailPatch,\n @Ctx() context: ResolverContext\n ): Promise<CommonCodeDetail> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(CommonCodeDetail)\n const commonCodeDetail = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n if (!commonCodeDetail) {\n throw new Error(`common code detail not found in this domain: ${id}`)\n }\n\n if (patch.commonCode && patch.commonCode.id) {\n patch.commonCode = await commonCodeInDomain(tx, domain, patch.commonCode.id)\n }\n\n return await repository.save({\n ...commonCodeDetail,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => [CommonCodeDetail], { description: \"To modify multiple CommonCodeDetails' information\" })\n async updateMultipleCommonCodeDetail(\n @Arg('patches', type => [CommonCodeDetailPatch]) patches: CommonCodeDetailPatch[],\n @Ctx() context: ResolverContext\n ): Promise<CommonCodeDetail[]> {\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 commonCodeDetailRepo = tx.getRepository(CommonCodeDetail)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n // 기존 description 필드 - 현재 locale로 기본값 넣어줌\n if (!newRecord.description) {\n newRecord.description = newRecord.labels[user.locale] || ''\n }\n\n if (newRecord.commonCode && newRecord.commonCode.id) {\n newRecord.commonCode = await commonCodeInDomain(tx, domain, newRecord.commonCode.id)\n }\n\n const result = await commonCodeDetailRepo.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 newRecord = _updateRecords[i]\n const commonCodeDetail = await commonCodeDetailRepo.findOne({\n where: { domain: { id: domain.id }, id: newRecord.id }\n })\n if (!commonCodeDetail) {\n throw new Error(`common code detail not found in this domain: ${newRecord.id}`)\n }\n\n // 기존 description 필드 - 현재 locale로 기본값 넣어줌\n if (!commonCodeDetail.description) {\n newRecord.description = newRecord.labels[user.locale] || ''\n }\n\n if (newRecord.commonCode && newRecord.commonCode.id) {\n newRecord.commonCode = await commonCodeInDomain(tx, domain, newRecord.commonCode.id)\n }\n\n const result = await commonCodeDetailRepo.save({\n ...commonCodeDetail,\n ...newRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete CommonCodeDetail' })\n async deleteCommonCodeDetail(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(CommonCodeDetail).delete({ domain: { id: domain.id }, id })\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete multiple CommonCodeDetails' })\n async deleteCommonCodeDetails(\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(CommonCodeDetail).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"common-code\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To import multiple CommonCodeDetails' })\n async importCommonCodeDetails(\n @Arg('commonCodeDetails', type => [CommonCodeDetailPatch]) commonCodeDetails: CommonCodeDetailPatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n commonCodeDetails.map(async (commonCodeDetail: CommonCodeDetailPatch) => {\n const createdCommonCodeDetail: CommonCodeDetail = await tx\n .getRepository(CommonCodeDetail)\n .save({ domain, ...commonCodeDetail })\n })\n )\n\n return true\n }\n}\n"]}