UNPKG

sgnm-neo4j-excel

Version:
847 lines 117 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Neo4jExcelService = void 0; const common_1 = require("@nestjs/common"); const neo4j_driver_1 = __importStar(require("neo4j-driver")); const neo4j_constants_1 = require("./neo4j.constants"); const transaction_1 = __importDefault(require("neo4j-driver-core/lib/transaction")); const common_func_1 = require("./func/common.func"); const import_export_error_enum_1 = require("./constant/import-export.error.enum"); const import_export_error_object_1 = require("./constant/import-export.error.object"); const filter_properties_type_enum_1 = require("./constant/filter.properties.type.enum"); const exceljs = require("exceljs"); const { v4: uuidv4 } = require("uuid"); const moment = require("moment"); let Neo4jExcelService = class Neo4jExcelService { constructor(config, driver) { this.getValueFromRichText = (datas) => __awaiter(this, void 0, void 0, function* () { try { let returningDatas = []; for (let i = 0; i < datas.length; i++) { if (typeof datas[i] == "object") { returningDatas.push(datas[i].text); } else { returningDatas.push(datas[i]); } } return returningDatas; } catch (error) { throw new common_1.HttpException(error, 500); } }); this.driver = driver; this.config = config; } getDriver() { return this.driver; } getConfig() { return this.config; } int(value) { return (0, neo4j_driver_1.int)(value); } beginTransaction(database) { const session = this.getWriteSession(database); return session.beginTransaction(); } getReadSession(database) { return this.driver.session({ database: database || this.config.database, defaultAccessMode: neo4j_driver_1.default.session.READ, }); } getWriteSession(database) { return this.driver.session({ database: database || this.config.database, defaultAccessMode: neo4j_driver_1.default.session.WRITE, }); } read(cypher, params, databaseOrTransaction) { if (databaseOrTransaction instanceof transaction_1.default) { return databaseOrTransaction.run(cypher, params); } const session = this.getReadSession(databaseOrTransaction); return session.run(cypher, params); } write(cypher, params, databaseOrTransaction) { if (databaseOrTransaction instanceof transaction_1.default) { return databaseOrTransaction.run(cypher, params); } const session = this.getWriteSession(databaseOrTransaction); return session.run(cypher, params); } onApplicationShutdown() { return this.driver.close(); } findChildrensByLabelsAndFilters() { return __awaiter(this, arguments, void 0, function* (root_labels = [], root_filters = {}, children_labels = [], children_filters = {}, relation_name, relation_filters = {}, relation_depth = "", databaseOrTransaction) { var _a, _b, _c; try { const rootLabelsWithoutEmptyString = (0, common_func_1.filterArrayForEmptyString)(root_labels); const childrenLabelsWithoutEmptyString = (0, common_func_1.filterArrayForEmptyString)(children_labels); const cypher = `MATCH p=(n` + (0, common_func_1.dynamicLabelAdder)(rootLabelsWithoutEmptyString) + (0, common_func_1.dynamicFilterPropertiesAdder)(root_filters) + `-[r:${relation_name}*1..${relation_depth}` + (0, common_func_1.dynamicFilterPropertiesAdderAndAddParameterKey)(relation_filters, filter_properties_type_enum_1.FilterPropertiesType.RELATION, '2') + ` ]->(m` + (0, common_func_1.dynamicLabelAdder)(childrenLabelsWithoutEmptyString) + (0, common_func_1.dynamicFilterPropertiesAdderAndAddParameterKey)(children_filters) + ` RETURN n as parent,m as children,r as relation`; children_filters = (0, common_func_1.changeObjectKeyName)(children_filters); relation_filters = (0, common_func_1.changeObjectKeyName)(relation_filters, '2'); const parameters = Object.assign(Object.assign(Object.assign({}, root_filters), children_filters), relation_filters); const result = yield this.read(cypher, parameters, databaseOrTransaction); return result["records"]; } catch (error) { if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.code) { throw new common_1.HttpException({ message: (_b = error.response) === null || _b === void 0 ? void 0 : _b.message, code: (_c = error.response) === null || _c === void 0 ? void 0 : _c.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getTypesExcel(res, body, header) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; try { let data = []; const { typeKeys } = body; const { username, language, realm } = header; for (let key of typeKeys) { let newData = yield this.getTypesByRealmAndByLanguage(realm, key, language, username); if (newData instanceof Error) { throw new common_1.HttpException(import_export_error_object_1.there_is_no_type_object, 404); } else { data = [...data, ...newData]; } } let workbook = new exceljs.Workbook(); let worksheet = workbook.addWorksheet("Types"); worksheet.columns = [ { header: "Type Name", key: "typeName", width: 50 }, { header: "Model Name", key: "modelNumber", width: 50 }, { header: "Super Set", key: "superSet", width: 50 }, { header: "Description", key: "description", width: 50 }, { header: "Warranty Duration Parts", key: "warrantyDurationParts", width: 50, }, { header: "Warranty Duration Labor", key: "warrantyDurationLabor", width: 50, }, { header: "Omni Category", key: "omniCategory", width: 50 }, { header: "Asset Type", key: "assetType", width: 50 }, { header: "Type Category", key: "typeCategory", width: 50 }, { header: "Brand", key: "brand", width: 50 }, { header: "Duration Unit", key: "durationUnit", width: 50 }, { header: "Warranty Duration Unit", key: "warrantyDurationUnit", width: 50 }, { header: "Measurement Unit", key: "measurementUnit", width: 50 }, { header: "Created At", key: "createdAt", width: 50 }, ]; worksheet.addRows(data); return workbook.xlsx.write(res).then(function () { res.status(200).end(); }); } catch (error) { if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.code) { throw new common_1.HttpException({ message: (_b = error.response) === null || _b === void 0 ? void 0 : _b.message, code: (_c = error.response) === null || _c === void 0 ? void 0 : _c.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getTypesByRealmAndByLanguage(realm, typeKey, language, userName) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d; try { let data; let jsonData = []; let cypher = `WITH 'MATCH (c:Asset {realm:"${realm}"})-[:PARENT_OF {isDeleted:false}]->(b:Types) MATCH path = (b)-[:PARENT_OF {isDeleted:false}]->(m:Type {key:"${typeKey}"})-[:CLASSIFIED_BY| ASSET_TYPE_BY| WARRANTY_DURATION_UNIT_BY | TYPE_CLASSIFIED_BY| BRAND_BY | DURATION_UNIT_BY | MEASUREMENT_UNIT_BY {isDeleted:false}]->(z) where z.language="${language}" and m.isDeleted=false and not (m:Component) WITH collect(path) AS paths CALL apoc.convert.toTree(paths) YIELD value RETURN value' AS query CALL apoc.export.json.query(query,'/${userName}.json',{jsonFormat:'ARRAY_JSON'}) YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data`; yield this.write(cypher); let cypher2 = `CALL apoc.load.json("${userName}.json")`; let returnData = yield this.read(cypher2); data = yield returnData.records[0]["_fields"][0]; if (data.length == 0) { throw new common_1.HttpException(import_export_error_object_1.there_is_no_type_object, 404); } else { for (let index = 0; index < ((_a = data.value.parent_of) === null || _a === void 0 ? void 0 : _a.length); index++) { let typeProperties = data.value.parent_of[index]; jsonData.push({ typeName: typeProperties.name, modelNumber: typeProperties.modelNumber, superSet: typeProperties.superSet, description: typeProperties.description, warrantyDurationParts: typeProperties.warrantyDurationParts, warrantyDurationLabor: typeProperties.warrantyDurationLabor, omniCategory: typeProperties.classified_by[0].name, assetType: typeProperties.asset_type_by[0].name, typeCategory: typeProperties.type_classified_by[0].name, brand: typeProperties.brand_by[0].name, durationUnit: typeProperties.duration_unit_by[0].name, warrantyDurationUnit: typeProperties.warranty_duration_unit_by[0].name, measurementUnit: typeProperties.measurement_unit_by[0].name, createdAt: typeProperties.createdAt, }); } return jsonData; } } catch (error) { if ((_b = error.response) === null || _b === void 0 ? void 0 : _b.code) { throw new common_1.HttpException({ message: (_c = error.response) === null || _c === void 0 ? void 0 : _c.message, code: (_d = error.response) === null || _d === void 0 ? void 0 : _d.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getComponentsExcel(res, body, header) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; let data = []; const { typeKeys } = body; const { username, realm } = header; try { for (let key of typeKeys) { let newData = yield this.getComponentsOfTypeWithTypekey(realm, key, username); if (newData instanceof Error) { throw new common_1.HttpException(import_export_error_object_1.there_are_no_type_or_component_or_type_id_is_wrong_object, 404); } else { data = [...data, ...newData]; } } let workbook = new exceljs.Workbook(); let worksheet = workbook.addWorksheet("Components"); worksheet.columns = [ { header: "Type Name", key: "typeName", width: 50 }, { header: "Component Name", key: "componentName", width: 50 }, { header: "Space Name", key: "spaceName", width: 50 }, { header: "Description", key: "description", width: 50 }, { header: "AssetIdentifier", key: "assetIdentifier", width: 50 }, { header: "Serial No", key: "serialNo", width: 50 }, { header: "Warranty Duration Labor", key: "warrantyDurationLabor", width: 50, }, { header: "Warranty Duration Parts", key: "warrantyDurationParts", width: 50, }, ]; worksheet.addRows(data); return workbook.xlsx.write(res).then(function () { res.status(200).end(); }); } catch (error) { if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.code) { throw new common_1.HttpException({ message: (_b = error.response) === null || _b === void 0 ? void 0 : _b.message, code: (_c = error.response) === null || _c === void 0 ? void 0 : _c.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getComponentsOfTypeWithTypekey(realm, typeKey, username) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { let data; let jsonData = []; let cypher = `WITH 'MATCH (a:Asset {realm:"${realm}"})-[:PARENT_OF {isDeleted:false}]->(b:Types) MATCH path = (b)-[:PARENT_OF {isDeleted:false}]->(t:Type {key:"${typeKey}"})-[:PARENT_OF {isDeleted:false}]->(c:Component)-[:WARRANTY_GUARANTOR_LABOR_BY | WARRANTY_GUARANTOR_PARTS_BY | LOCATED_IN {isDeleted:false}]->(x) where t.isDeleted=false and c.isDeleted=false WITH collect(path) AS paths CALL apoc.convert.toTree(paths) YIELD value RETURN value' AS query CALL apoc.export.json.query(query,'/${username}.json',{jsonFormat:'ARRAY_JSON'}) YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data`; yield this.write(cypher); let cypher2 = `CALL apoc.load.json("${username}.json")`; let returnData = yield this.read(cypher2); data = yield returnData.records[0]["_fields"][0]; if (data.length == 0) { throw new common_1.HttpException(import_export_error_object_1.there_are_no_type_or_component_or_type_id_is_wrong_object, 404); } else { for (let j = 0; j < ((_a = data.value.parent_of) === null || _a === void 0 ? void 0 : _a.length); j++) { for (let i = 0; i < ((_b = data.value.parent_of[j].parent_of) === null || _b === void 0 ? void 0 : _b.length); i++) { let componentProperties = data.value.parent_of[j].parent_of[i]; jsonData.push({ typeName: data.value.parent_of[j].name, componentName: componentProperties.name, spaceName: componentProperties.located_in[0].name, description: componentProperties.description, assetIdentifier: componentProperties.assetIdentifier, serialNo: componentProperties.serialNo, warrantyDurationLabor: componentProperties.warrantyDurationLabor, warrantyDurationParts: componentProperties.warrantyDurationParts, }); } } return jsonData; } } catch (error) { if ((_c = error.response) === null || _c === void 0 ? void 0 : _c.code) { throw new common_1.HttpException({ message: (_d = error.response) === null || _d === void 0 ? void 0 : _d.message, code: (_e = error.response) === null || _e === void 0 ? void 0 : _e.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getSparesWithExcel(res, body, header) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; let data = []; const { typeKeys } = body; const { username, realm, language } = header; try { for (let key of typeKeys) { let newData = yield this.getSparesOfTypeWithTypekey(realm, key, username, language); if (newData instanceof Error) { throw new common_1.HttpException(import_export_error_object_1.there_are_no_type_or_component_or_type_id_is_wrong_object, 404); } else { data = [...data, ...newData]; } } let workbook = new exceljs.Workbook(); let worksheet = workbook.addWorksheet("Spares"); worksheet.columns = [ { header: "Type Name", key: "typeName", width: 50 }, { header: "Spare Name", key: "spareName", width: 50 }, { header: "Space Name", key: "spaceName", width: 50 }, { header: "Count", key: "count", width: 50 }, { header: "Description", key: "description", width: 50 }, { header: "PartNumber", key: "partNumber", width: 50 }, { header: "SetNumber", key: "setNumber", width: 50 }, ]; worksheet.addRows(data); return workbook.xlsx.write(res).then(function () { res.status(200).end(); }); } catch (error) { if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.code) { throw new common_1.HttpException({ message: (_b = error.response) === null || _b === void 0 ? void 0 : _b.message, code: (_c = error.response) === null || _c === void 0 ? void 0 : _c.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getSparesOfTypeWithTypekey(realm, typeKey, username, language) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { let data; let jsonData = []; let cypher = `WITH 'MATCH (a:Asset {realm:"${realm}"})-[:PARENT_OF {isDeleted:false}]->(b:Types) MATCH path = (b)-[:PARENT_OF {isDeleted:false}]->(t:Type {key:"${typeKey}"})-[:PARENT_OF {isDeleted:false}]->(c:Spare)-[:CLASSIFIED_BY | STORED_IN {isDeleted:false}]->(x) where (x.language="${language}" or not exists(x.language)) and t.isDeleted=false and c.isDeleted=false WITH collect(path) AS paths CALL apoc.convert.toTree(paths) YIELD value RETURN value' AS query CALL apoc.export.json.query(query,'/${username}.json',{jsonFormat:'ARRAY_JSON'}) YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data`; yield this.write(cypher); let cypher2 = `CALL apoc.load.json("${username}.json")`; let returnData = yield this.read(cypher2); data = yield returnData.records[0]["_fields"][0]; if (data.length == 0) { throw new common_1.HttpException(import_export_error_object_1.there_are_no_type_or_component_or_type_id_is_wrong_object, 404); } else { for (let j = 0; j < ((_a = data.value.parent_of) === null || _a === void 0 ? void 0 : _a.length); j++) { for (let i = 0; i < ((_b = data.value.parent_of[j].parent_of) === null || _b === void 0 ? void 0 : _b.length); i++) { let spareProperties = data.value.parent_of[j].parent_of[i]; jsonData.push({ typeName: data.value.parent_of[j].name, spareName: spareProperties.name, spaceName: spareProperties.stored_in[0].name, count: spareProperties.count, description: spareProperties.description, partNumber: spareProperties.partNumber, setNumber: spareProperties.setNumber, }); } } return jsonData; } } catch (error) { if ((_c = error.response) === null || _c === void 0 ? void 0 : _c.code) { throw new common_1.HttpException({ message: (_d = error.response) === null || _d === void 0 ? void 0 : _d.message, code: (_e = error.response) === null || _e === void 0 ? void 0 : _e.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getResourcesWithExcel(res, body, header) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; let data = []; const { typeKeys } = body; const { username, realm, language } = header; try { for (let key of typeKeys) { let newData = yield this.getResourcesOfTypeWithTypeKey(realm, key, username, language); if (newData instanceof Error) { throw new common_1.HttpException("", 404); } else { data = [...data, ...newData]; } } let workbook = new exceljs.Workbook(); let worksheet = workbook.addWorksheet("Resources"); worksheet.columns = [ { header: "Type Name", key: "typeName", width: 50 }, { header: "Resource Name", key: "resourceName", width: 50 }, { header: "Space Name", key: "spaceName", width: 50 }, { header: "Count", key: "count", width: 50 }, { header: "Measurement Unit", key: "measurementUnit", width: 50 }, { header: "Description", key: "description", width: 50 }, { header: "SetNumber", key: "setNumber", width: 50 }, ]; worksheet.addRows(data); return workbook.xlsx.write(res).then(function () { res.status(200).end(); }); } catch (error) { if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.code) { throw new common_1.HttpException({ message: (_b = error.response) === null || _b === void 0 ? void 0 : _b.message, code: (_c = error.response) === null || _c === void 0 ? void 0 : _c.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getResourcesOfTypeWithTypeKey(realm, typeKey, username, language) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { let data; let jsonData = []; let cypher = `WITH 'MATCH (a:Asset {realm:"${realm}"})-[:PARENT_OF {isDeleted:false}]->(b:Types) MATCH path = (b)-[:PARENT_OF {isDeleted:false}]->(t:Type {key:"${typeKey}"})-[:PARENT_OF {isDeleted:false}]->(c:Resource)-[:CLASSIFIED_BY | STORED_IN | MEASUREMENT_UNIT_BY {isDeleted:false}]->(x) where (x.language="${language}" or not exists(x.language)) and t.isDeleted=false and c.isDeleted=false WITH collect(path) AS paths CALL apoc.convert.toTree(paths) YIELD value RETURN value' AS query CALL apoc.export.json.query(query,'/${username}.json',{jsonFormat:'ARRAY_JSON'}) YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data`; yield this.write(cypher); let cypher2 = `CALL apoc.load.json("${username}.json")`; let returnData = yield this.read(cypher2); data = yield returnData.records[0]["_fields"][0]; if (data.length == 0) { throw new common_1.HttpException("", 404); } else { for (let j = 0; j < ((_a = data.value.parent_of) === null || _a === void 0 ? void 0 : _a.length); j++) { for (let i = 0; i < ((_b = data.value.parent_of[j].parent_of) === null || _b === void 0 ? void 0 : _b.length); i++) { let resourceProperties = data.value.parent_of[j].parent_of[i]; jsonData.push({ typeName: data.value.parent_of[j].name, resourceName: resourceProperties.name, spaceName: resourceProperties.stored_in[0].name, count: resourceProperties.count, measurementUnit: resourceProperties.measurement_unit_by[0].name, description: resourceProperties.description, setNumber: resourceProperties.setNumber, }); } } return jsonData; } } catch (error) { if ((_c = error.response) === null || _c === void 0 ? void 0 : _c.code) { throw new common_1.HttpException({ message: (_d = error.response) === null || _d === void 0 ? void 0 : _d.message, code: (_e = error.response) === null || _e === void 0 ? void 0 : _e.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getSystemsExcel(res, body, header) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; let data = []; const { systemKeys } = body; const { username, realm } = header; try { for (let key of systemKeys) { let newData = yield this.getSystemsByKey(realm, key, username); if (newData instanceof Error) { throw new common_1.HttpException(import_export_error_object_1.there_are_no_system_or_component_or_type_object, 404); } else { data = [...data, ...newData]; } } let workbook = new exceljs.Workbook(); let worksheet = workbook.addWorksheet("Systems"); worksheet.columns = [ { header: "System Name", key: "systemName", width: 50 }, { header: "System Description", key: "systemDescription", width: 50 }, { header: "Creator", key: "creator", width: 50 }, { header: "Type Name", key: "typeName", width: 50 }, { header: "Component Name", key: "componentName", width: 50 }, { header: "Space Name", key: "spaceName", width: 50 }, { header: "Description", key: "description", width: 50 }, { header: "Serial No", key: "serialNo", width: 50 }, { header: "Warranty Duration Labor", key: "warrantyDurationLabor", width: 50, }, { header: "Warranty Duration Parts", key: "warrantyDurationParts", width: 50, }, ]; worksheet.addRows(data); return workbook.xlsx.write(res).then(function () { res.status(200).end(); }); } catch (error) { if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.code) { throw new common_1.HttpException({ message: (_b = error.response) === null || _b === void 0 ? void 0 : _b.message, code: (_c = error.response) === null || _c === void 0 ? void 0 : _c.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getSystemsByKey(realm, systemKey, username) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g; try { let data; let jsonData = []; let cypher = `WITH 'MATCH (a:Asset {realm:"${realm}"})-[:PARENT_OF {isDeleted:false}]->(b:Systems)-[:PARENT_OF* {isDeleted:false}]->(s:System {key:"${systemKey}",isDeleted:false}) MATCH path = (s)-[:SYSTEM_OF | TYPE_OF_SYSTEM | CREATED_BY {isDeleted:false}]->(ct) where ct.isDeleted=false WITH collect(path) AS paths CALL apoc.convert.toTree(paths) YIELD value RETURN value' AS query CALL apoc.export.json.query(query,'/${username}.json',{jsonFormat:'ARRAY_JSON'}) YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data`; yield this.write(cypher); let cypher2 = `CALL apoc.load.json("${username}.json")`; let returnData = yield this.read(cypher2); data = yield returnData.records[0]["_fields"][0]; console.log(data); if (data.length == 0) { throw new common_1.HttpException(import_export_error_object_1.there_are_no_system_or_component_or_type_object, 404); } else { if (((_a = data.value.system_of) === null || _a === void 0 ? void 0 : _a.length) > 0) { for (let c = 0; c < ((_b = data.value.system_of) === null || _b === void 0 ? void 0 : _b.length); c++) { let componentProperties = data.value.system_of[c]; jsonData.push({ systemName: data.value.name, systemDescription: data.value.description, creator: data.value.created_by[0].name, typeName: "", componentName: componentProperties.name, spaceName: componentProperties.spaceName, description: componentProperties.description, serialNo: componentProperties.serialNumber, warrantyDurationLabor: componentProperties.warrantyDurationLabor.low, warrantyDurationParts: componentProperties.warrantyDurationParts.low, }); } } if (((_c = data.value.type_of_system) === null || _c === void 0 ? void 0 : _c.length) > 0) { for (let c = 0; c < ((_d = data.value.type_of_system) === null || _d === void 0 ? void 0 : _d.length); c++) { let typeProperties = data.value.type_of_system[c]; jsonData.push({ systemName: data.value.name, systemDescription: data.value.description, creator: data.value.created_by[0].name, typeName: typeProperties.name ? typeProperties.name : "", componentName: "", spaceName: "", description: "", serialNo: "", warrantyDurationLabor: "", warrantyDurationParts: "", }); } } return jsonData; } } catch (error) { if ((_e = error.response) === null || _e === void 0 ? void 0 : _e.code) { throw new common_1.HttpException({ message: (_f = error.response) === null || _f === void 0 ? void 0 : _f.message, code: (_g = error.response) === null || _g === void 0 ? void 0 : _g.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getSpacesByBuilding(realm, username, buildingKey, language) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; try { let data; let jsonData = []; let buildingType = []; let cypher = `WITH 'MATCH (c:FacilityStructure {realm:"${realm}"})-[:PARENT_OF {isDeleted:false}]->(b {key:"${buildingKey}",isDeleted:false}) MATCH path = (b)-[:PARENT_OF* {isDeleted:false}]->(m)-[:CLASSIFIED_BY| CREATED_BY {isDeleted:false}]->(z) where (z.language="${language}" or not exists(z.language)) and m.isDeleted=false and not (m:JointSpaces OR m:JointSpace OR m:Zones or m:Zone) WITH collect(path) AS paths CALL apoc.convert.toTree(paths) YIELD value RETURN value' AS query CALL apoc.export.json.query(query,'/${username}.json',{jsonFormat:'ARRAY_JSON'}) YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data`; yield this.write(cypher); let cypher2 = `CALL apoc.load.json("${username}.json")`; let returnData = yield this.read(cypher2); data = yield returnData.records[0]["_fields"][0]; if (data.value.parent_of == undefined || (((_a = data.value.parent_of[0]) === null || _a === void 0 ? void 0 : _a.nodeType) == "Floor" && typeof data.value.parent_of[0].parent_of == "undefined") || (((_b = data.value.parent_of[0]) === null || _b === void 0 ? void 0 : _b.nodeType) == "Block" && (typeof data.value.parent_of[0].parent_of == "undefined" || typeof data.value.parent_of[0].parent_of[0].parent_of == "undefined"))) { throw new common_1.HttpException(import_export_error_object_1.there_are_no_spaces_object, 404); } else { if (((_d = (_c = data.value.parent_of[0]) === null || _c === void 0 ? void 0 : _c.parent_of[0]) === null || _d === void 0 ? void 0 : _d.parent_of) == undefined) { for (let index = 0; index < ((_e = data.value.parent_of) === null || _e === void 0 ? void 0 : _e.length); index++) { for (let i = 0; i < ((_f = data.value.parent_of[index].parent_of) === null || _f === void 0 ? void 0 : _f.length); i++) { buildingType.push({ 1: data.value.nodeType, 2: data.value.parent_of[index].nodeType, 3: data.value.parent_of[index].parent_of[i].nodeType, }); } } } else { for (let index = 0; index < ((_g = data.value.parent_of) === null || _g === void 0 ? void 0 : _g.length); index++) { for (let i = 0; i < ((_h = data.value.parent_of[index].parent_of) === null || _h === void 0 ? void 0 : _h.length); i++) { for (let a = 0; a < ((_j = data.value.parent_of[index].parent_of[i].parent_of) === null || _j === void 0 ? void 0 : _j.length); a++) { buildingType.push({ 1: data.value.nodeType, 2: data.value.parent_of[index].nodeType, 3: data.value.parent_of[index].parent_of[i].nodeType, 4: data.value.parent_of[index].parent_of[i].parent_of[a] .nodeType, }); } } } } let typeList = yield Object.values(buildingType[0]); if (!typeList.includes("Block")) { for (let index = 0; index < ((_k = data.value.parent_of) === null || _k === void 0 ? void 0 : _k.length); index++) { for (let i = 0; i < ((_l = data.value.parent_of[index].parent_of) === null || _l === void 0 ? void 0 : _l.length); i++) { let spaceProperties = data.value.parent_of[index].parent_of[i]; jsonData.push({ buildingName: data.value.name, blockName: "-", floorName: data.value.parent_of[index].name, spaceName: spaceProperties.name, code: spaceProperties.code ? spaceProperties.code : " ", architecturalName: spaceProperties.architecturalName, architecturalCode: spaceProperties.architecturalCode ? spaceProperties.architecturalCode : " ", category: spaceProperties.classified_by[0].name, grossArea: spaceProperties.grossArea.low, netArea: spaceProperties.netArea.low, usage: spaceProperties.usage ? spaceProperties.usage : " ", tag: spaceProperties.tag.toString(), roomTag: spaceProperties.roomTag.toString(), status: spaceProperties.status ? spaceProperties.status : " ", operatorName: spaceProperties.operatorName ? spaceProperties.operatorName : " ", operatorCode: spaceProperties.operatorCode ? spaceProperties.operatorCode : " ", description: spaceProperties.description, usableHeight: spaceProperties.usableHeight.low, externalSystem: spaceProperties.externalSystem, externalObject: spaceProperties.externalObject, externalIdentifier: spaceProperties.externalIdentifier, createdAt: spaceProperties.createdAt, createdBy: spaceProperties.created_by[0].email, }); } } } else { for (let index = 0; index < ((_m = data.value.parent_of) === null || _m === void 0 ? void 0 : _m.length); index++) { for (let i = 0; i < ((_p = (_o = data.value.parent_of[index]) === null || _o === void 0 ? void 0 : _o.parent_of) === null || _p === void 0 ? void 0 : _p.length); i++) { for (let a = 0; a < ((_s = (_r = (_q = data.value.parent_of[index]) === null || _q === void 0 ? void 0 : _q.parent_of[i]) === null || _r === void 0 ? void 0 : _r.parent_of) === null || _s === void 0 ? void 0 : _s.length); a++) { let spaceProperties = (_u = (_t = data.value.parent_of[index]) === null || _t === void 0 ? void 0 : _t.parent_of[i]) === null || _u === void 0 ? void 0 : _u.parent_of[a]; jsonData.push({ buildingName: data.value.name, blockName: data.value.parent_of[index].name, floorName: data.value.parent_of[index].parent_of[i].name, spaceName: data.value.parent_of[index].parent_of[i].parent_of[a].name, code: spaceProperties.code ? spaceProperties.code : " ", architecturalName: spaceProperties.architecturalName, architecturalCode: spaceProperties.architecturalCode ? spaceProperties.architecturalCode : " ", category: spaceProperties.classified_by[0].name, grossArea: spaceProperties.grossArea, netArea: spaceProperties.netArea, usage: spaceProperties.usage ? spaceProperties.usage : " ", tag: spaceProperties.tag.toString(), roomTag: spaceProperties.roomTag.toString(), status: spaceProperties.status ? spaceProperties.status : " ", operatorName: spaceProperties.operatorName ? spaceProperties.operatorName : " ", operatorCode: spaceProperties.operatorCode ? spaceProperties.operatorCode : " ", description: spaceProperties.description, usableHeight: spaceProperties.usableHeight, externalSystem: spaceProperties.externalSystem, externalObject: spaceProperties.externalObject, externalIdentifier: spaceProperties.externalIdentifier, createdAt: spaceProperties.createdAt, createdBy: spaceProperties.created_by[0].email, }); } } } } return jsonData; } } catch (error) { if ((_v = error.response) === null || _v === void 0 ? void 0 : _v.code) { throw new common_1.HttpException({ message: (_w = error.response) === null || _w === void 0 ? void 0 : _w.message, code: (_x = error.response) === null || _x === void 0 ? void 0 : _x.code }, error.status); } else { throw new common_1.HttpException(error, 500); } } }); } getJointSpacesByBuilding(realm, username, buildingKey, language) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { let data; let jsonData = []; let cypher = `WITH 'MATCH (c:FacilityStructure {realm:"${realm}"})-[:PARENT_OF {isDeleted:false}]->(b {key:"${buildingKey}",isDeleted:false}) MATCH path = (b)-[:PARENT_OF* {isDeleted:false}]->(m)-[:CLASSIFIED_BY| CREATED_BY {isDeleted:false}]->(z) where (z.language="${language}" or not exists(z.language)) and m.isDeleted=false and not (m:Space OR m:Zone OR m:Zones OR m:Floor OR m:Block) WITH collect(path) AS paths CALL apoc.convert.toTree(paths) YIELD value RETURN value' AS query CALL apoc.export.json.query(query,'/${username}.json',{jsonFormat:'ARRAY_JSON'}) YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data`; yield this.write(cypher); let cypher2 = `CALL apoc.load.json("${username}.