@things-factory/operato-board 6.0.111 → 6.0.113

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.
@@ -0,0 +1,39 @@
1
+ var licenseKey = require('./config/license').Key
2
+ module.exports = {
3
+ accessTokenCookieKey: 'access_token.board',
4
+ licenseKey: licenseKey,
5
+ scheduler: {
6
+ /* Name to be used for setting client's "application" properties when registering a schedule */
7
+ application: 'operato-board',
8
+ /* Base endpoint to be used for setting "callback" properties when registering a schedule */
9
+ callbackBase: 'http://localhost:3000',
10
+ /*
11
+ Scheduler service endpoint
12
+ caution) endpoint for "localhost" has some problem.
13
+ https://github.com/node-fetch/node-fetch/issues/1624
14
+ */
15
+ endpoint: 'http://127.0.0.1:9902'
16
+ }
17
+ // ormconfig: {
18
+ // name: 'default',
19
+ // type: 'postgres',
20
+ // host: '127.0.0.1',
21
+ // port: 5432,
22
+ // database: 'vis_app',
23
+ // username: 'postgres',
24
+ // password: 'hatioLAB1008',
25
+ // synchronize: true,
26
+ // logging: true
27
+ // },
28
+ // ormconfig4Tx: {
29
+ // name: 'default',
30
+ // type: 'postgres',
31
+ // host: '127.0.0.1',
32
+ // port: 5432,
33
+ // database: 'vis_app',
34
+ // username: 'postgres',
35
+ // password: 'hatioLAB1008',
36
+ // synchronize: false,
37
+ // logging: true
38
+ // }
39
+ }
@@ -0,0 +1,33 @@
1
+ var licenseKey = require('./config/license').Key
2
+
3
+ module.exports = {
4
+ licenseKey: licenseKey,
5
+ protocol: 'https',
6
+ accessTokenCookieKey: 'access_token.board',
7
+ email: {
8
+ host: 'smtp.office365.com', // your sender-email smtp host
9
+ port: 587, // smtp server port
10
+ secure: false, // true for 465, false for other ports
11
+ auth: {
12
+ user: 'your sender-email',
13
+ pass: 'your sender-email password' // generated ethereal password
14
+ },
15
+ secureConnection: false,
16
+ tls: {
17
+ ciphers: 'SSLv3'
18
+ }
19
+ },
20
+ logger: {
21
+ file: {
22
+ filename: 'logs/application-%DATE%.log',
23
+ datePattern: 'YYYY-MM-DD-HH',
24
+ zippedArchive: false,
25
+ maxSize: '20m',
26
+ maxFiles: '2d',
27
+ level: 'info'
28
+ },
29
+ console: {
30
+ level: 'silly'
31
+ }
32
+ }
33
+ }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BoardResolver = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const typeorm_1 = require("typeorm");
5
6
  const type_graphql_1 = require("type-graphql");
6
7
  const board_service_1 = require("@things-factory/board-service");
7
8
  const operato_license_checker_1 = require("@things-factory/operato-license-checker");
@@ -29,7 +30,7 @@ let BoardResolver = class BoardResolver {
29
30
  async board(id, context) {
30
31
  const { domain } = context.state;
31
32
  var board = await (0, shell_1.getRepository)(board_service_1.Board).findOne({
32
- where: { domain: { id: domain.id }, id }
33
+ where: { domain: { id: (0, typeorm_1.In)([domain.id, domain.parentId].filter(Boolean)) }, id }
33
34
  });
34
35
  if (domain) {
35
36
  // 1. check domainSecret is over limit quantity or not
@@ -1 +1 @@
1
- {"version":3,"file":"board-resolver.js","sourceRoot":"","sources":["../../../server/service/board-secret/board-resolver.ts"],"names":[],"mappings":";;;;AAAA,+CAAmE;AAEnE,iEAAqD;AACrD,qFAAiG;AACjG,iDAAqD;AAErD,8DAAyD;AACzD,kEAA6D;AAC7D,iDAA4C;AAC5C,yDAAgD;AAEhD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAGzB,IAAM,aAAa,GAAnB,MAAM,aAAa;IAElB,AAAN,KAAK,CAAC,gBAAgB,CAAQ,OAAwB;QACpD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEtC,MAAM,mBAAmB,GAAG,CAAC,IAAA,uCAAa,EAAC,6BAA6B,CAAC,IAAI,kBAAkB,CAAC;aAC7F,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE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AAA,IAAA,kBAAG,GAAE,CAAA;;;;qDAkB5B;AAIK;IAFL,IAAA,wBAAS,EAAC,6EAA6E,CAAC;IACxF,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,qBAAK,EAAE,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAChD,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0CA2GxC;AAnIU,aAAa;IADzB,IAAA,uBAAQ,EAAC,qBAAK,CAAC;GACH,aAAa,CAoIzB;AApIY,sCAAa","sourcesContent":["import { Arg, Ctx, Directive, Query, Resolver } from 'type-graphql'\n\nimport { Board } from '@things-factory/board-service'\nimport { checkTarget, doSomething, getPermission } from '@things-factory/operato-license-checker'\nimport { getRepository } from '@things-factory/shell'\n\nimport { LicenseError } from '../../errors/license-error'\nimport { DomainSecret } from '../domain-secret/domain-secret'\nimport { BoardSecret } from './board-secret'\nimport { User } from '@things-factory/auth-base'\n\nconst crypto = require('crypto')\n\n@Resolver(Board)\nexport class BoardResolver {\n @Query(returns => [String], { description: 'Board Usage Permissions' })\n async boardPermissions(@Ctx() context: ResolverContext): Promise<string[]> {\n const { user, domain } = context.state\n\n const licensedPermissions = (getPermission('Permissions For Board Usage') || 'Modeller, Viewer')\n .split(',')\n .map(p => p.trim())\n\n var permissions = []\n\n licensedPermissions.includes('Modeller') &&\n (await User.hasPrivilege('mutation', 'board', domain, user)) &&\n permissions.push('Modeller')\n\n licensedPermissions.includes('Viewer') &&\n (await User.hasPrivilege('query', 'board', domain, user)) &&\n permissions.push('Viewer')\n\n return permissions\n }\n\n @Directive('@privilege(category: \"board\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Board, { description: 'To fetch a board' })\n async board(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Board> {\n const { domain } = context.state\n\n var board = await getRepository(Board).findOne({\n where: { domain: { id: domain.id }, id }\n })\n if (domain) {\n // 1. check domainSecret is over limit quantity or not\n var count =\n (await getRepository(DomainSecret)\n .manager.createQueryBuilder()\n .select('board')\n .from(DomainSecret, 'secret')\n .where('id = :domainId', { domainId: domain.id })\n .getCount()) + 1\n\n if (!checkTarget(count)) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.OVER_LIMIT)\n })\n } else {\n var domainSecret: DomainSecret = await getRepository(DomainSecret).findOne({\n where: { domain: { id: domain.id } }\n })\n // 2. if there's no domainSecret then create it\n if (!domainSecret) {\n var domainSecret: DomainSecret = new DomainSecret()\n domainSecret.id = crypto.randomUUID()\n domainSecret.domain = domain\n var hash = doSomething({ secId: domainSecret.id, id: domain.id })\n domainSecret.secret = hash\n\n await getRepository(DomainSecret).save(domainSecret)\n // 3. if there's domainSecret then check it\n } else {\n var domainRepo = getRepository(DomainSecret)\n var domainSecret: DomainSecret = await domainRepo.findOne({\n where: { domain: { id: domain.id } }\n })\n if (domainSecret) {\n var hash = doSomething({ secId: domainSecret.id, id: domain.id })\n if (domainSecret.secret !== hash) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n } else {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n }\n }\n }\n if (board) {\n // 1. check boardSecret is over limit quantity or not\n var count =\n (await getRepository(BoardSecret)\n .manager.createQueryBuilder()\n .select('board')\n .from(BoardSecret, 'secret')\n .where('domain_id = :domainId', { domainId: domain.id })\n .getCount()) + 1\n\n if (!checkTarget(count)) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.OVER_LIMIT)\n })\n } else {\n var boardSecret: BoardSecret = await getRepository(BoardSecret).findOne({\n where: { targetId: id }\n })\n // 2. if there's no boardSecret then create it\n if (!boardSecret) {\n var boardSecret: BoardSecret = new BoardSecret()\n boardSecret.id = crypto.randomUUID()\n boardSecret.targetId = id\n boardSecret.targetType = 'board'\n boardSecret.domain = domain\n\n var hash = doSomething({ secId: boardSecret.id, id: id })\n boardSecret.secret = hash\n\n await getRepository(BoardSecret).save(boardSecret)\n // 3. if there's boardSecret then check it\n } else {\n var repogitory = getRepository(BoardSecret)\n var boardSecret: BoardSecret = await repogitory.findOne({\n where: { targetId: id }\n })\n if (boardSecret) {\n var hash = doSomething({ secId: boardSecret.id, id: id })\n if (boardSecret.secret !== hash) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n } else {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n }\n }\n }\n\n return board\n }\n}\n"]}
1
+ {"version":3,"file":"board-resolver.js","sourceRoot":"","sources":["../../../server/service/board-secret/board-resolver.ts"],"names":[],"mappings":";;;;AAAA,qCAA4B;AAC5B,+CAAmE;AAEnE,iEAAqD;AACrD,qFAAiG;AACjG,iDAAqD;AAErD,8DAAyD;AACzD,kEAA6D;AAC7D,iDAA4C;AAC5C,yDAAgD;AAEhD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAGzB,IAAM,aAAa,GAAnB,MAAM,aAAa;IAElB,AAAN,KAAK,CAAC,gBAAgB,CAAQ,OAAwB;QACpD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEtC,MAAM,mBAAmB,GAAG,CAAC,IAAA,uCAAa,EAAC,6BAA6B,CAAC,IAAI,kBAAkB,CAAC;aAC7F,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAErB,IAAI,WAAW,GAAG,EAAE,CAAA;QAEpB,mBAAmB,CAAC,QAAQ,CAAC,UAAU,CAAC;YACtC,CAAC,MAAM,gBAAI,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YA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AC,qBAAK,EAAE,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAChD,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0CA2GxC;AAnIU,aAAa;IADzB,IAAA,uBAAQ,EAAC,qBAAK,CAAC;GACH,aAAa,CAoIzB;AApIY,sCAAa","sourcesContent":["import { In } from 'typeorm'\nimport { Arg, Ctx, Directive, Query, Resolver } from 'type-graphql'\n\nimport { Board } from '@things-factory/board-service'\nimport { checkTarget, doSomething, getPermission } from '@things-factory/operato-license-checker'\nimport { getRepository } from '@things-factory/shell'\n\nimport { LicenseError } from '../../errors/license-error'\nimport { DomainSecret } from '../domain-secret/domain-secret'\nimport { BoardSecret } from './board-secret'\nimport { User } from '@things-factory/auth-base'\n\nconst crypto = require('crypto')\n\n@Resolver(Board)\nexport class BoardResolver {\n @Query(returns => [String], { description: 'Board Usage Permissions' })\n async boardPermissions(@Ctx() context: ResolverContext): Promise<string[]> {\n const { user, domain } = context.state\n\n const licensedPermissions = (getPermission('Permissions For Board Usage') || 'Modeller, Viewer')\n .split(',')\n .map(p => p.trim())\n\n var permissions = []\n\n licensedPermissions.includes('Modeller') &&\n (await User.hasPrivilege('mutation', 'board', domain, user)) &&\n permissions.push('Modeller')\n\n licensedPermissions.includes('Viewer') &&\n (await User.hasPrivilege('query', 'board', domain, user)) &&\n permissions.push('Viewer')\n\n return permissions\n }\n\n @Directive('@privilege(category: \"board\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Board, { description: 'To fetch a board' })\n async board(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Board> {\n const { domain } = context.state\n\n var board = await getRepository(Board).findOne({\n where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id }\n })\n if (domain) {\n // 1. check domainSecret is over limit quantity or not\n var count =\n (await getRepository(DomainSecret)\n .manager.createQueryBuilder()\n .select('board')\n .from(DomainSecret, 'secret')\n .where('id = :domainId', { domainId: domain.id })\n .getCount()) + 1\n\n if (!checkTarget(count)) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.OVER_LIMIT)\n })\n } else {\n var domainSecret: DomainSecret = await getRepository(DomainSecret).findOne({\n where: { domain: { id: domain.id } }\n })\n // 2. if there's no domainSecret then create it\n if (!domainSecret) {\n var domainSecret: DomainSecret = new DomainSecret()\n domainSecret.id = crypto.randomUUID()\n domainSecret.domain = domain\n var hash = doSomething({ secId: domainSecret.id, id: domain.id })\n domainSecret.secret = hash\n\n await getRepository(DomainSecret).save(domainSecret)\n // 3. if there's domainSecret then check it\n } else {\n var domainRepo = getRepository(DomainSecret)\n var domainSecret: DomainSecret = await domainRepo.findOne({\n where: { domain: { id: domain.id } }\n })\n if (domainSecret) {\n var hash = doSomething({ secId: domainSecret.id, id: domain.id })\n if (domainSecret.secret !== hash) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n } else {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n }\n }\n }\n if (board) {\n // 1. check boardSecret is over limit quantity or not\n var count =\n (await getRepository(BoardSecret)\n .manager.createQueryBuilder()\n .select('board')\n .from(BoardSecret, 'secret')\n .where('domain_id = :domainId', { domainId: domain.id })\n .getCount()) + 1\n\n if (!checkTarget(count)) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.OVER_LIMIT)\n })\n } else {\n var boardSecret: BoardSecret = await getRepository(BoardSecret).findOne({\n where: { targetId: id }\n })\n // 2. if there's no boardSecret then create it\n if (!boardSecret) {\n var boardSecret: BoardSecret = new BoardSecret()\n boardSecret.id = crypto.randomUUID()\n boardSecret.targetId = id\n boardSecret.targetType = 'board'\n boardSecret.domain = domain\n\n var hash = doSomething({ secId: boardSecret.id, id: id })\n boardSecret.secret = hash\n\n await getRepository(BoardSecret).save(boardSecret)\n // 3. if there's boardSecret then check it\n } else {\n var repogitory = getRepository(BoardSecret)\n var boardSecret: BoardSecret = await repogitory.findOne({\n where: { targetId: id }\n })\n if (boardSecret) {\n var hash = doSomething({ secId: boardSecret.id, id: id })\n if (boardSecret.secret !== hash) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n } else {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n }\n }\n }\n\n return board\n }\n}\n"]}
@@ -22,6 +22,9 @@ let DomainResolver = class DomainResolver {
22
22
  if (updateRecord.name) {
23
23
  updateRecord.subdomain = (0, utils_1.slugger)(updateRecord.name);
24
24
  }
25
+ if (updateRecord.parent && updateRecord.parent.id == domain.id) {
26
+ delete updateRecord.parent;
27
+ }
25
28
  await domainRepo.save(Object.assign(Object.assign({}, domain), updateRecord));
26
29
  });
27
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"domain-resolver.js","sourceRoot":"","sources":["../../../server/service/domain-secret/domain-resolver.ts"],"names":[],"mappings":";;;;AAAA,+CAAiE;AAGjE,iDAA0E;AAC1E,iDAA+C;AAGxC,IAAM,cAAc,GAApB,MAAM,cAAc;IAGnB,AAAN,KAAK,CAAC,aAAa,CAAwC,OAAsB;QAC/E,MAAM,UAAU,GAAuB,IAAA,qBAAa,EAAC,cAAM,CAAC,CAAA;QAE5D,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAChE,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAE/D,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,cAAc,CAAC,OAAO,CAAC,KAAK,EAAC,YAAY,EAAC,EAAE;gBAC1C,MAAM,SAAS,GAAW,IAAA,eAAO,EAAC,YAAY,CAAC,IAAI,CAAC,CAAA;gBAEpD,MAAM,UAAU,CAAC,IAAI,CAAC,gCAAK,YAAY,KAAE,SAAS,GAAS,CAAC,CAAA;YAC9D,CAAC,CAAC,CAAA;SACH;QAED,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,cAAc,CAAC,OAAO,CAAC,KAAK,EAAC,YAAY,EAAC,EAAE;gBAC1C,MAAM,MAAM,GAAW,MAAM,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;gBAEnF,IAAI,YAAY,CAAC,IAAI,EAAE;oBACrB,YAAY,CAAC,SAAS,GAAG,IAAA,eAAO,EAAC,YAAY,CAAC,IAAI,CAAC,CAAA;iBACpD;gBAED,MAAM,UAAU,CAAC,IAAI,CAAC,gCACjB,MAAM,GACN,YAAY,CACT,CAAC,CAAA;YACX,CAAC,CAAC,CAAA;SACH;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA;AA/BO;IAFL,IAAA,wBAAS,EAAC,+EAA+E,CAAC;IAC1F,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,4BAA4B,EAAE,CAAC;IACvD,mBAAA,IAAA,kBAAG,EAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,mBAAW,CAAC,CAAC,CAAA;;;;mDA8BzD;AAjCU,cAAc;IAD1B,IAAA,uBAAQ,EAAC,cAAM,CAAC;GACJ,cAAc,CAkC1B;AAlCY,wCAAc","sourcesContent":["import { Arg, Directive, Mutation, Resolver } from 'type-graphql'\nimport { Repository } from 'typeorm'\n\nimport { Domain, DomainPatch, getRepository } from '@things-factory/shell'\nimport { slugger } from '@things-factory/utils'\n\n@Resolver(Domain)\nexport class DomainResolver {\n @Directive('@privilege(category: \"system\", privilege: \"mutation\", superUserGranted: true)')\n @Mutation(returns => Boolean, { description: 'To update multiple domains' })\n async updateDomains(@Arg('patches', type => [DomainPatch]) patches: DomainPatch[]): Promise<boolean> {\n const domainRepo: Repository<Domain> = getRepository(Domain)\n\n const _createRecords = patches.filter((patch: any) => !patch.id)\n const _updateRecords = patches.filter((patch: any) => patch.id)\n\n if (_createRecords.length > 0) {\n _createRecords.forEach(async createRecord => {\n const subdomain: string = slugger(createRecord.name)\n\n await domainRepo.save({ ...createRecord, subdomain } as any)\n })\n }\n\n if (_updateRecords.length > 0) {\n _updateRecords.forEach(async updateRecord => {\n const domain: Domain = await domainRepo.findOne({ where: { id: updateRecord.id } })\n\n if (updateRecord.name) {\n updateRecord.subdomain = slugger(updateRecord.name)\n }\n\n await domainRepo.save({\n ...domain,\n ...updateRecord\n } as any)\n })\n }\n\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"domain-resolver.js","sourceRoot":"","sources":["../../../server/service/domain-secret/domain-resolver.ts"],"names":[],"mappings":";;;;AAAA,+CAAiE;AAGjE,iDAA0E;AAC1E,iDAA+C;AAGxC,IAAM,cAAc,GAApB,MAAM,cAAc;IAGnB,AAAN,KAAK,CAAC,aAAa,CAAwC,OAAsB;QAC/E,MAAM,UAAU,GAAuB,IAAA,qBAAa,EAAC,cAAM,CAAC,CAAA;QAE5D,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAChE,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAE/D,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,cAAc,CAAC,OAAO,CAAC,KAAK,EAAC,YAAY,EAAC,EAAE;gBAC1C,MAAM,SAAS,GAAW,IAAA,eAAO,EAAC,YAAY,CAAC,IAAI,CAAC,CAAA;gBAEpD,MAAM,UAAU,CAAC,IAAI,CAAC,gCAAK,YAAY,KAAE,SAAS,GAAS,CAAC,CAAA;YAC9D,CAAC,CAAC,CAAA;SACH;QAED,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,cAAc,CAAC,OAAO,CAAC,KAAK,EAAC,YAAY,EAAC,EAAE;gBAC1C,MAAM,MAAM,GAAW,MAAM,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;gBAEnF,IAAI,YAAY,CAAC,IAAI,EAAE;oBACrB,YAAY,CAAC,SAAS,GAAG,IAAA,eAAO,EAAC,YAAY,CAAC,IAAI,CAAC,CAAA;iBACpD;gBAED,IAAI,YAAY,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,EAAE,EAAE;oBAC9D,OAAO,YAAY,CAAC,MAAM,CAAA;iBAC3B;gBAED,MAAM,UAAU,CAAC,IAAI,CAAC,gCACjB,MAAM,GACN,YAAY,CACT,CAAC,CAAA;YACX,CAAC,CAAC,CAAA;SACH;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA;AAnCO;IAFL,IAAA,wBAAS,EAAC,+EAA+E,CAAC;IAC1F,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,4BAA4B,EAAE,CAAC;IACvD,mBAAA,IAAA,kBAAG,EAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,mBAAW,CAAC,CAAC,CAAA;;;;mDAkCzD;AArCU,cAAc;IAD1B,IAAA,uBAAQ,EAAC,cAAM,CAAC;GACJ,cAAc,CAsC1B;AAtCY,wCAAc","sourcesContent":["import { Arg, Directive, Mutation, Resolver } from 'type-graphql'\nimport { Repository } from 'typeorm'\n\nimport { Domain, DomainPatch, getRepository } from '@things-factory/shell'\nimport { slugger } from '@things-factory/utils'\n\n@Resolver(Domain)\nexport class DomainResolver {\n @Directive('@privilege(category: \"system\", privilege: \"mutation\", superUserGranted: true)')\n @Mutation(returns => Boolean, { description: 'To update multiple domains' })\n async updateDomains(@Arg('patches', type => [DomainPatch]) patches: DomainPatch[]): Promise<boolean> {\n const domainRepo: Repository<Domain> = getRepository(Domain)\n\n const _createRecords = patches.filter((patch: any) => !patch.id)\n const _updateRecords = patches.filter((patch: any) => patch.id)\n\n if (_createRecords.length > 0) {\n _createRecords.forEach(async createRecord => {\n const subdomain: string = slugger(createRecord.name)\n\n await domainRepo.save({ ...createRecord, subdomain } as any)\n })\n }\n\n if (_updateRecords.length > 0) {\n _updateRecords.forEach(async updateRecord => {\n const domain: Domain = await domainRepo.findOne({ where: { id: updateRecord.id } })\n\n if (updateRecord.name) {\n updateRecord.subdomain = slugger(updateRecord.name)\n }\n\n if (updateRecord.parent && updateRecord.parent.id == domain.id) {\n delete updateRecord.parent\n }\n\n await domainRepo.save({\n ...domain,\n ...updateRecord\n } as any)\n })\n }\n\n return true\n }\n}\n"]}