From 51b6c9db003c74fce638f240c49426b39862baaa Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Fri, 12 Jan 2024 13:48:08 -0300 Subject: [PATCH 01/20] fix:add customerId in user table --- build/interfaces.d.ts | 1 + build/users/services/createUserService.js | 1 + build/users/validationUserModel.js | 1 + src/interfaces.ts | 1 + src/users/services/createUserService.ts | 1 + src/users/validationUserModel.ts | 1 + 6 files changed, 6 insertions(+) diff --git a/build/interfaces.d.ts b/build/interfaces.d.ts index bcaac28..8dc7412 100644 --- a/build/interfaces.d.ts +++ b/build/interfaces.d.ts @@ -15,6 +15,7 @@ export interface IUsers { complement: string; quota: UserQuota; validatedMail: boolean; + customerId: string; [key: string]: any; } export interface IEntityDb { diff --git a/build/users/services/createUserService.js b/build/users/services/createUserService.js index 0ba4235..d964f6b 100644 --- a/build/users/services/createUserService.js +++ b/build/users/services/createUserService.js @@ -43,6 +43,7 @@ function createUserService(user) { imageUsedMB: 0, pointCloudUsedMB: 0, }, + customerId: user.customerId }); const savedUser = yield newUser.save(); return savedUser; diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js index bc43485..2bbca45 100644 --- a/build/users/validationUserModel.js +++ b/build/users/validationUserModel.js @@ -27,6 +27,7 @@ const UserSchema = new mongoose_1.default.Schema({ imageUsedMB: { type: Number, required: true }, BIMUsedMB: { type: Number, required: true }, }, + customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, }); const UserModel = mongoose_1.default.model('user', UserSchema); diff --git a/src/interfaces.ts b/src/interfaces.ts index 9db3202..79740e4 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -15,6 +15,7 @@ export interface IUsers { complement: string quota: UserQuota validatedMail: boolean + customerId:string [key: string]: any } diff --git a/src/users/services/createUserService.ts b/src/users/services/createUserService.ts index 7356f0e..19271ea 100644 --- a/src/users/services/createUserService.ts +++ b/src/users/services/createUserService.ts @@ -34,6 +34,7 @@ export async function createUserService(user: IUsers): Promise { imageUsedMB: 0, pointCloudUsedMB: 0, }, + customerId:user.customerId }) const savedUser = await newUser.save() diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index b22779f..b28b1c6 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -23,6 +23,7 @@ const UserSchema = new mongoose.Schema({ imageUsedMB: { type: Number, required: true }, BIMUsedMB: { type: Number, required: true }, }, + customerId:{type:String, required:false}, validatedMail: { type: Boolean, required: true, default: false }, }) From e1ad2b5d37a4510cf100f4cff899e1730379c4ae Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Fri, 12 Jan 2024 13:51:38 -0300 Subject: [PATCH 02/20] fix: format --- src/interfaces.ts | 2 +- src/users/services/createUserService.ts | 2 +- src/users/validationUserModel.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index 79740e4..91176fc 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -15,7 +15,7 @@ export interface IUsers { complement: string quota: UserQuota validatedMail: boolean - customerId:string + customerId: string [key: string]: any } diff --git a/src/users/services/createUserService.ts b/src/users/services/createUserService.ts index 19271ea..026e283 100644 --- a/src/users/services/createUserService.ts +++ b/src/users/services/createUserService.ts @@ -34,7 +34,7 @@ export async function createUserService(user: IUsers): Promise { imageUsedMB: 0, pointCloudUsedMB: 0, }, - customerId:user.customerId + customerId: user.customerId, }) const savedUser = await newUser.save() diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index b28b1c6..9d56fc0 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -23,7 +23,7 @@ const UserSchema = new mongoose.Schema({ imageUsedMB: { type: Number, required: true }, BIMUsedMB: { type: Number, required: true }, }, - customerId:{type:String, required:false}, + customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, }) From 08e4c2dc4a818b31c8f0cc0043454fd2937d594b Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Sat, 13 Jan 2024 12:54:41 -0300 Subject: [PATCH 03/20] feat:CustomerId service --- build/connection.d.ts | 3 - build/connection.js | 50 ----- build/entity/services/EntityService.d.ts | 58 ------ build/entity/services/EntityService.js | 173 ------------------ build/entity/validationEntityDb.d.ts | 1 - build/entity/validationEntityDb.js | 83 --------- build/entity/validationEntityModel.d.ts | 29 --- build/entity/validationEntityModel.js | 15 -- build/index.d.ts | 24 --- build/index.js | 43 ----- build/interfaces.d.ts | 109 ----------- build/interfaces.js | 32 ---- .../services/OrganizationService.d.ts | 39 ---- .../services/OrganizationService.js | 118 ------------ build/organizations/validationOrgDb.d.ts | 1 - build/organizations/validationOrgDb.js | 82 --------- build/organizations/validationOrgModel.d.ts | 29 --- build/organizations/validationOrgModel.js | 18 -- build/projects/services/ProjectService.d.ts | 43 ----- build/projects/services/ProjectService.js | 156 ---------------- build/projects/validationProjectsDb.d.ts | 1 - build/projects/validationProjectsDb.js | 140 -------------- build/projects/validationProjectsModel.d.ts | 29 --- build/projects/validationProjectsModel.js | 28 --- build/users/services/createUserService.d.ts | 2 - build/users/services/createUserService.js | 60 ------ build/users/services/deleteUserService.d.ts | 28 --- build/users/services/deleteUserService.js | 27 --- build/users/services/getOneUserService.d.ts | 28 --- build/users/services/getOneUserService.js | 28 --- build/users/services/getUsersService.d.ts | 28 --- build/users/services/getUsersService.js | 28 --- build/users/services/loginService.d.ts | 2 - build/users/services/loginService.js | 28 --- build/users/services/updateUserService.d.ts | 2 - build/users/services/updateUserService.js | 58 ------ build/users/validationDbUsers.d.ts | 1 - build/users/validationDbUsers.js | 121 ------------ build/users/validationUserModel.d.ts | 4 - build/users/validationUserModel.js | 34 ---- build/usersProject/UserService.d.ts | 34 ---- build/usersProject/UserService.js | 57 ------ src/index.ts | 2 + src/users/services/updateCustomerIdService.ts | 27 +++ 44 files changed, 29 insertions(+), 1874 deletions(-) delete mode 100644 build/connection.d.ts delete mode 100644 build/connection.js delete mode 100644 build/entity/services/EntityService.d.ts delete mode 100644 build/entity/services/EntityService.js delete mode 100644 build/entity/validationEntityDb.d.ts delete mode 100644 build/entity/validationEntityDb.js delete mode 100644 build/entity/validationEntityModel.d.ts delete mode 100644 build/entity/validationEntityModel.js delete mode 100644 build/index.d.ts delete mode 100644 build/index.js delete mode 100644 build/interfaces.d.ts delete mode 100644 build/interfaces.js delete mode 100644 build/organizations/services/OrganizationService.d.ts delete mode 100644 build/organizations/services/OrganizationService.js delete mode 100644 build/organizations/validationOrgDb.d.ts delete mode 100644 build/organizations/validationOrgDb.js delete mode 100644 build/organizations/validationOrgModel.d.ts delete mode 100644 build/organizations/validationOrgModel.js delete mode 100644 build/projects/services/ProjectService.d.ts delete mode 100644 build/projects/services/ProjectService.js delete mode 100644 build/projects/validationProjectsDb.d.ts delete mode 100644 build/projects/validationProjectsDb.js delete mode 100644 build/projects/validationProjectsModel.d.ts delete mode 100644 build/projects/validationProjectsModel.js delete mode 100644 build/users/services/createUserService.d.ts delete mode 100644 build/users/services/createUserService.js delete mode 100644 build/users/services/deleteUserService.d.ts delete mode 100644 build/users/services/deleteUserService.js delete mode 100644 build/users/services/getOneUserService.d.ts delete mode 100644 build/users/services/getOneUserService.js delete mode 100644 build/users/services/getUsersService.d.ts delete mode 100644 build/users/services/getUsersService.js delete mode 100644 build/users/services/loginService.d.ts delete mode 100644 build/users/services/loginService.js delete mode 100644 build/users/services/updateUserService.d.ts delete mode 100644 build/users/services/updateUserService.js delete mode 100644 build/users/validationDbUsers.d.ts delete mode 100644 build/users/validationDbUsers.js delete mode 100644 build/users/validationUserModel.d.ts delete mode 100644 build/users/validationUserModel.js delete mode 100644 build/usersProject/UserService.d.ts delete mode 100644 build/usersProject/UserService.js create mode 100644 src/users/services/updateCustomerIdService.ts diff --git a/build/connection.d.ts b/build/connection.d.ts deleted file mode 100644 index 5edda3e..0000000 --- a/build/connection.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare function connectToDatabase(url: string, databaseName: string): Promise; -export declare function checkConnectionStatus(): void; -export declare function subscribeToDatabaseEvents(): void; diff --git a/build/connection.js b/build/connection.js deleted file mode 100644 index 560ad28..0000000 --- a/build/connection.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; -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.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = void 0; -const mongoose_1 = __importDefault(require("mongoose")); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function connectToDatabase(url, databaseName) { - return __awaiter(this, void 0, void 0, function* () { - try { - yield mongoose_1.default.connect(`${url}/${databaseName}`, {}); - console.log(`Conectado ao banco de dados: ${databaseName}`); - } - catch (error) { - throw error; - } - }); -} -exports.connectToDatabase = connectToDatabase; -function checkConnectionStatus() { - // 1 -> Connected - if (mongoose_1.default.connection.readyState != 1) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = `MongoDB disconnected`; - throw err; - } -} -exports.checkConnectionStatus = checkConnectionStatus; -function subscribeToDatabaseEvents() { - mongoose_1.default.connection.on('connected', () => { - console.log(`⚡️[database]: MongoDB connected`); - }); - mongoose_1.default.connection.on('error', (error) => { - console.log(`⚡️[database]: MongoDB Error - ${error}`); - }); - mongoose_1.default.connection.on('disconnected', () => { - console.log(`⚡️[database]: MongoDB Disconnected`); - }); -} -exports.subscribeToDatabaseEvents = subscribeToDatabaseEvents; diff --git a/build/entity/services/EntityService.d.ts b/build/entity/services/EntityService.d.ts deleted file mode 100644 index 1cfec63..0000000 --- a/build/entity/services/EntityService.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IEntityDb } from '../../interfaces'; -export declare class EntityService { - protected model: import("mongoose").Model & IEntityDb & Required<{ - _id: string; - }>, any>; - protected configure(): void; - insert(entity: IEntityDb): Promise; - get(entity_id: string): Promise; - getByName(project_id: string, entity_name: string): Promise; - update(entity: IEntityDb): Promise; - remove(entity_id: string): Promise; - removeAllFromUser(user_id: string): Promise; - exists(entity_id: string): Promise; - existsWithName(project_id: string, entity_name: string): Promise; - listAllFromProject(project_id: string): Promise; - /** - * Assign a parent entity to another entity. This essentially - * makes them a `child` entity. Child entities are not allowed - * to be processed. (business logic) - * - * @param project_id - * @param entity_name - * @param parent_entity_name - */ - assignParentName(project_id: string, entity_name: string, parent_entity_name: string): Promise; - /** - * Promote entity. Removes the parent field and allows them to be processed - * (business logic) - * @param project_id - * @param entity_name - */ - promoteEntity(project_id: string, entity_name: string): Promise; -} diff --git a/build/entity/services/EntityService.js b/build/entity/services/EntityService.js deleted file mode 100644 index 1e4da80..0000000 --- a/build/entity/services/EntityService.js +++ /dev/null @@ -1,173 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.EntityService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const connection_1 = require("../../connection"); -const validationEntityModel_1 = require("../validationEntityModel"); -class EntityService { - constructor() { - this.model = validationEntityModel_1.entityModel; - } - configure() { } - insert(entity) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entity_record = new this.model(entity); - yield entity_record.save(); - return entity_record.toJSON(); - }); - } - get(entity_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entity_record = yield this.model.findById(entity_id).lean().exec(); - if (!entity_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - throw err; - } - return entity_record; - }); - } - getByName(project_id, entity_name) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entity_record = yield this.model - .findOne({ projectId: project_id, name: entity_name }) - .lean() - .exec(); - if (!entity_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - throw err; - } - return entity_record; - }); - } - update(entity) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entity_record = yield this.model - .findByIdAndUpdate(entity._id, entity, { - new: true, - }) - .lean() - .exec(); - if (!entity_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - throw err; - } - return entity_record; - }); - } - remove(entity_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = yield this.exists(entity_id); - if (!exists) { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - throw err; - } - yield this.model.findByIdAndRemove(entity_id); - }); - } - removeAllFromUser(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - yield this.model.deleteMany({ user_id: user_id }); - }); - } - exists(entity_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = (yield this.model.exists({ _id: entity_id }).lean().exec()) != null; - return exists; - }); - } - existsWithName(project_id, entity_name) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project = yield this.model - .findOne({ projectId: project_id, name: entity_name }) - .lean() - .exec(); - return project != null; - }); - } - listAllFromProject(project_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entities = yield this.model - .find({ proje: project_id }) - .lean() - .exec(); - return entities; - }); - } - /** - * Assign a parent entity to another entity. This essentially - * makes them a `child` entity. Child entities are not allowed - * to be processed. (business logic) - * - * @param project_id - * @param entity_name - * @param parent_entity_name - */ - assignParentName(project_id, entity_name, parent_entity_name) { - return __awaiter(this, void 0, void 0, function* () { - // Check if entity exist. - const child_entity = yield this.getByName(project_id, entity_name); - if (!(yield this.existsWithName(project_id, parent_entity_name))) { - { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - err.Details = `Parent Name: ${parent_entity_name}`; - throw err; - } - } - child_entity.parentName = parent_entity_name; - this.update(child_entity); - }); - } - /** - * Promote entity. Removes the parent field and allows them to be processed - * (business logic) - * @param project_id - * @param entity_name - */ - promoteEntity(project_id, entity_name) { - return __awaiter(this, void 0, void 0, function* () { - // Check if entity exist. - const child_entity = yield this.getByName(project_id, entity_name); - if (child_entity.parentName === undefined) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = - 'Entity is not a chilld, or does not have parent property.'; - throw err; - } - const entity = yield this.model.findOne({ - projectId: project_id, - name: entity_name, - }); - // Assigning document properties to undefined removes them. - entity.parentName = undefined; - yield entity.save(); - }); - } -} -exports.EntityService = EntityService; diff --git a/build/entity/validationEntityDb.d.ts b/build/entity/validationEntityDb.d.ts deleted file mode 100644 index 666cb38..0000000 --- a/build/entity/validationEntityDb.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function createEntityCollectionWithValidation(uri: string, databaseName: string, collectionName: string): Promise; diff --git a/build/entity/validationEntityDb.js b/build/entity/validationEntityDb.js deleted file mode 100644 index 04c8ee6..0000000 --- a/build/entity/validationEntityDb.js +++ /dev/null @@ -1,83 +0,0 @@ -"use strict"; -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.createEntityCollectionWithValidation = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -const mongodb_1 = require("mongodb"); -dotenv_1.default.config(); -function createEntityCollectionWithValidation(uri, databaseName, collectionName) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(uri); - yield client.connect(); - const db = client.db(databaseName); - const colecao = db.collection(collectionName); - const validationRules = { - validator: { - $jsonSchema: { - bsonType: 'object', - required: [ - 'projectId', - 'type', - 'name', - 'location', - 'sizeMB', - 'shareGroup', - ], - properties: { - projectId: { - bsonType: 'string', - description: 'Project ID must be a string and is required.', - }, - type: { - bsonType: 'string', - description: 'Type must be a string and is required.', - }, - name: { - bsonType: 'string', - description: 'Name must be a string and is required.', - }, - location: { - bsonType: 'string', - description: 'Location must be a string and is required.', - }, - sizeMB: { - bsonType: 'number', - description: 'SizeMB must be a number and is required.', - }, - shareGroup: { - bsonType: 'string', - description: 'Share group must be a string and is required.', - }, - parentName: { - bsonType: 'string', - description: 'Holds a name reference to a parent entity. Not required.', - }, - }, - }, - }, - validationLevel: 'strict', - validationAction: 'error', - }; - yield colecao.createIndex({ projectId: 1 }); - yield db.command({ - collMod: colecao.collectionName, - validator: validationRules.validator, - validationLevel: validationRules.validationLevel, - validationAction: validationRules.validationAction, - }); - console.log(`Collection ${collectionName} with validation rules created successfully.`); - yield client.close(); - }); -} -exports.createEntityCollectionWithValidation = createEntityCollectionWithValidation; diff --git a/build/entity/validationEntityModel.d.ts b/build/entity/validationEntityModel.d.ts deleted file mode 100644 index 1a56a9c..0000000 --- a/build/entity/validationEntityModel.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IEntityDb } from '../interfaces'; -export declare const entityModel: import("mongoose").Model & IEntityDb & Required<{ - _id: string; -}>, any>; diff --git a/build/entity/validationEntityModel.js b/build/entity/validationEntityModel.js deleted file mode 100644 index ee39e35..0000000 --- a/build/entity/validationEntityModel.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.entityModel = void 0; -const mongoose_1 = require("mongoose"); -const entitySchema = new mongoose_1.Schema({ - _id: { type: String, required: true }, - projectId: { type: String, required: true, index: true }, - type: { type: String, required: true }, - name: { type: String, required: true }, - location: { type: String, required: true }, - sizeMB: { type: Number, required: true }, - shareGroup: { type: String, required: true }, - parentName: { type: String, requred: false }, -}); -exports.entityModel = (0, mongoose_1.model)('entity', entitySchema); diff --git a/build/index.d.ts b/build/index.d.ts deleted file mode 100644 index 71b6d97..0000000 --- a/build/index.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { createUserCollectionWithValidation } from './users/validationDbUsers'; -import { UserModel } from './users/validationUserModel'; -import { IMemberDb, IUser, IUsers } from './interfaces'; -import { connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents } from './connection'; -import { IEntityDb } from './interfaces'; -import { IProjectDb } from './interfaces'; -import { IOrganizationDb } from './interfaces'; -import { entityModel } from './entity/validationEntityModel'; -import { projectModel } from './projects/validationProjectsModel'; -import { organizationModel } from './organizations/validationOrgModel'; -import { createEntityCollectionWithValidation } from './entity/validationEntityDb'; -import { createProjectCollectionWithValidation } from './projects/validationProjectsDb'; -import { createOrganizationCollectionWithValidation } from './organizations/validationOrgDb'; -import { createUserService } from './users/services/createUserService'; -import { getUserByEmail } from './users/services/loginService'; -import { deleteUserService } from './users/services/deleteUserService'; -import { getOneUserService } from './users/services/getOneUserService'; -import { getUsersService } from './users/services/getUsersService'; -import { EntityService } from './entity/services/EntityService'; -import { ProjectService } from './projects/services/ProjectService'; -import { OrganizationService } from './organizations/services/OrganizationService'; -import { updateUserService } from './users/services/updateUserService'; -import { UserService } from './usersProject/UserService'; -export { createUserCollectionWithValidation, connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents, createEntityCollectionWithValidation, createProjectCollectionWithValidation, createOrganizationCollectionWithValidation, deleteUserService, getOneUserService, getUsersService, createUserService, updateUserService, getUserByEmail, UserService, OrganizationService, EntityService, ProjectService, UserModel, entityModel, organizationModel, IUsers, IUser, IEntityDb, IProjectDb, projectModel, IOrganizationDb, IMemberDb, }; diff --git a/build/index.js b/build/index.js deleted file mode 100644 index 7a8c03c..0000000 --- a/build/index.js +++ /dev/null @@ -1,43 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.projectModel = exports.organizationModel = exports.entityModel = exports.UserModel = exports.ProjectService = exports.EntityService = exports.OrganizationService = exports.UserService = exports.getUserByEmail = exports.updateUserService = exports.createUserService = exports.getUsersService = exports.getOneUserService = exports.deleteUserService = exports.createOrganizationCollectionWithValidation = exports.createProjectCollectionWithValidation = exports.createEntityCollectionWithValidation = exports.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = exports.createUserCollectionWithValidation = void 0; -const validationDbUsers_1 = require("./users/validationDbUsers"); -Object.defineProperty(exports, "createUserCollectionWithValidation", { enumerable: true, get: function () { return validationDbUsers_1.createUserCollectionWithValidation; } }); -const validationUserModel_1 = require("./users/validationUserModel"); -Object.defineProperty(exports, "UserModel", { enumerable: true, get: function () { return validationUserModel_1.UserModel; } }); -const connection_1 = require("./connection"); -Object.defineProperty(exports, "connectToDatabase", { enumerable: true, get: function () { return connection_1.connectToDatabase; } }); -Object.defineProperty(exports, "checkConnectionStatus", { enumerable: true, get: function () { return connection_1.checkConnectionStatus; } }); -Object.defineProperty(exports, "subscribeToDatabaseEvents", { enumerable: true, get: function () { return connection_1.subscribeToDatabaseEvents; } }); -const validationEntityModel_1 = require("./entity/validationEntityModel"); -Object.defineProperty(exports, "entityModel", { enumerable: true, get: function () { return validationEntityModel_1.entityModel; } }); -const validationProjectsModel_1 = require("./projects/validationProjectsModel"); -Object.defineProperty(exports, "projectModel", { enumerable: true, get: function () { return validationProjectsModel_1.projectModel; } }); -const validationOrgModel_1 = require("./organizations/validationOrgModel"); -Object.defineProperty(exports, "organizationModel", { enumerable: true, get: function () { return validationOrgModel_1.organizationModel; } }); -const validationEntityDb_1 = require("./entity/validationEntityDb"); -Object.defineProperty(exports, "createEntityCollectionWithValidation", { enumerable: true, get: function () { return validationEntityDb_1.createEntityCollectionWithValidation; } }); -const validationProjectsDb_1 = require("./projects/validationProjectsDb"); -Object.defineProperty(exports, "createProjectCollectionWithValidation", { enumerable: true, get: function () { return validationProjectsDb_1.createProjectCollectionWithValidation; } }); -const validationOrgDb_1 = require("./organizations/validationOrgDb"); -Object.defineProperty(exports, "createOrganizationCollectionWithValidation", { enumerable: true, get: function () { return validationOrgDb_1.createOrganizationCollectionWithValidation; } }); -const createUserService_1 = require("./users/services/createUserService"); -Object.defineProperty(exports, "createUserService", { enumerable: true, get: function () { return createUserService_1.createUserService; } }); -const loginService_1 = require("./users/services/loginService"); -Object.defineProperty(exports, "getUserByEmail", { enumerable: true, get: function () { return loginService_1.getUserByEmail; } }); -const deleteUserService_1 = require("./users/services/deleteUserService"); -Object.defineProperty(exports, "deleteUserService", { enumerable: true, get: function () { return deleteUserService_1.deleteUserService; } }); -const getOneUserService_1 = require("./users/services/getOneUserService"); -Object.defineProperty(exports, "getOneUserService", { enumerable: true, get: function () { return getOneUserService_1.getOneUserService; } }); -const getUsersService_1 = require("./users/services/getUsersService"); -Object.defineProperty(exports, "getUsersService", { enumerable: true, get: function () { return getUsersService_1.getUsersService; } }); -const EntityService_1 = require("./entity/services/EntityService"); -Object.defineProperty(exports, "EntityService", { enumerable: true, get: function () { return EntityService_1.EntityService; } }); -const ProjectService_1 = require("./projects/services/ProjectService"); -Object.defineProperty(exports, "ProjectService", { enumerable: true, get: function () { return ProjectService_1.ProjectService; } }); -const OrganizationService_1 = require("./organizations/services/OrganizationService"); -Object.defineProperty(exports, "OrganizationService", { enumerable: true, get: function () { return OrganizationService_1.OrganizationService; } }); -const updateUserService_1 = require("./users/services/updateUserService"); -Object.defineProperty(exports, "updateUserService", { enumerable: true, get: function () { return updateUserService_1.updateUserService; } }); -const UserService_1 = require("./usersProject/UserService"); -Object.defineProperty(exports, "UserService", { enumerable: true, get: function () { return UserService_1.UserService; } }); diff --git a/build/interfaces.d.ts b/build/interfaces.d.ts deleted file mode 100644 index 8dc7412..0000000 --- a/build/interfaces.d.ts +++ /dev/null @@ -1,109 +0,0 @@ -export interface IUsers { - _id: string; - name: string; - lastName: string; - email: string; - password: string; - actingField: string; - phoneNumber: string; - postalCode: string; - useObjective: string; - imagePath: string; - cep: string; - street: string; - number: string; - complement: string; - quota: UserQuota; - validatedMail: boolean; - customerId: string; - [key: string]: any; -} -export interface IEntityDb { - _id: string; - projectId: string; - type: EntityType; - name: string; - location: string; - sizeMB: number; - shareGroup: ShareGroupType; - parentName?: string; -} -/** - * Project level quota. Contains summed up entity sized. - */ -export interface ProjectQuota { - pointCloudUsedMB: number; - imageUsedMB: number; - BIMUsedMB: number; -} -/** - * User level quota. Contains quota and used space from all projects. - */ -export interface UserQuota { - pointCloudQuotaMB: number; - imageSizeQuotaMB: number; - BIMSizeQuotaMB: number; - pointCloudUsedMB: number; - imageUsedMB: number; - BIMUsedMB: number; -} -export interface IProjectDb { - _id: string; - user_id: string; - name: string; - clientName: string; - type: string; - snapshot?: string; - favorite: boolean; - clouds: Array; - images: Array; - bim: Array; - projectQuota: ProjectQuota; - createdAt: number; - modifiedAt: number; - publicAccessToken: string; - status: ProjectStatus; - owner?: string; - accessType?: ProjectAccessType; -} -export interface IOrganizationDb { - _id: string; - memberLimit: number; - members: Array; - name: string; - type: string; -} -export interface IMemberDb { - user: string; - role: OrganizationMemberRole; -} -export interface IUser { - _id: string; - name: string; - lastName: string; - email: string; -} -export declare enum OrganizationMemberRole { - VIEWER = "VIEWER", - EDITOR = "EDITOR", - ADMIN = "ADMIN", - OWNER = "OWNER" -} -export declare enum ProjectStatus { - IN_PROGRESS = "IN_PROGRESS", - FINISHED = "FINISHED" -} -export declare enum ProjectAccessType { - INTERNAL = "INTERNAL", - PRIVATE = "PRIVATE" -} -export declare enum ShareGroupType { - Public = "public", - Private = "private" -} -export declare enum EntityType { - PointCloud = "clouds", - Image = "images", - BIM = "bim", - Unknown = "unknown" -} diff --git a/build/interfaces.js b/build/interfaces.js deleted file mode 100644 index 21cd19e..0000000 --- a/build/interfaces.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.EntityType = exports.ShareGroupType = exports.ProjectAccessType = exports.ProjectStatus = exports.OrganizationMemberRole = void 0; -var OrganizationMemberRole; -(function (OrganizationMemberRole) { - OrganizationMemberRole["VIEWER"] = "VIEWER"; - OrganizationMemberRole["EDITOR"] = "EDITOR"; - OrganizationMemberRole["ADMIN"] = "ADMIN"; - OrganizationMemberRole["OWNER"] = "OWNER"; -})(OrganizationMemberRole || (exports.OrganizationMemberRole = OrganizationMemberRole = {})); -var ProjectStatus; -(function (ProjectStatus) { - ProjectStatus["IN_PROGRESS"] = "IN_PROGRESS"; - ProjectStatus["FINISHED"] = "FINISHED"; -})(ProjectStatus || (exports.ProjectStatus = ProjectStatus = {})); -var ProjectAccessType; -(function (ProjectAccessType) { - ProjectAccessType["INTERNAL"] = "INTERNAL"; - ProjectAccessType["PRIVATE"] = "PRIVATE"; -})(ProjectAccessType || (exports.ProjectAccessType = ProjectAccessType = {})); -var ShareGroupType; -(function (ShareGroupType) { - ShareGroupType["Public"] = "public"; - ShareGroupType["Private"] = "private"; -})(ShareGroupType || (exports.ShareGroupType = ShareGroupType = {})); -var EntityType; -(function (EntityType) { - EntityType["PointCloud"] = "clouds"; - EntityType["Image"] = "images"; - EntityType["BIM"] = "bim"; - EntityType["Unknown"] = "unknown"; -})(EntityType || (exports.EntityType = EntityType = {})); diff --git a/build/organizations/services/OrganizationService.d.ts b/build/organizations/services/OrganizationService.d.ts deleted file mode 100644 index afa244a..0000000 --- a/build/organizations/services/OrganizationService.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IOrganizationDb } from '../../interfaces'; -export declare class OrganizationService { - protected model: import("mongoose").Model & IOrganizationDb & Required<{ - _id: string; - }>, any>; - protected configure(): void; - insert(organization: IOrganizationDb): Promise; - get(organization_id: string): Promise; - getPopulated(organization_id: string): Promise; - update(organization: IOrganizationDb): Promise; - remove(organization_id: string): Promise; - exists(organization_id: string): Promise; - listAllFromUser(user_id: string): Promise>; -} diff --git a/build/organizations/services/OrganizationService.js b/build/organizations/services/OrganizationService.js deleted file mode 100644 index daa61a6..0000000 --- a/build/organizations/services/OrganizationService.js +++ /dev/null @@ -1,118 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.OrganizationService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const connection_1 = require("../../connection"); -const validationOrgModel_1 = require("../validationOrgModel"); -const validationUserModel_1 = require("../../users/validationUserModel"); -class OrganizationService { - constructor() { - this.model = validationOrgModel_1.organizationModel; - } - configure() { } - insert(organization) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organization_record = new this.model(organization); - yield organization_record.save(); - return organization_record.toJSON(); - }); - } - get(organization_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organization_record = yield this.model - .findById(organization_id) - .lean() - .exec(); - if (!organization_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; - err.Details = `Organization '${organization_id}' not found'`; - throw err; - } - return organization_record; - }); - } - getPopulated(organization_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organization_record = yield this.model - .findById(organization_id) - .populate({ - path: 'members.user', - model: validationUserModel_1.UserModel, - select: '_id name lastName email', - }) - .lean() - .exec(); - if (!organization_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; - err.Details = `Organization '${organization_id}' not found'`; - throw err; - } - return organization_record; - }); - } - update(organization) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organization_record = yield this.model.findByIdAndUpdate(organization._id, organization, { - new: true, - }); - if (!organization_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; - err.Details = `Organization '${organization._id}' not found'`; - throw err; - } - return organization_record.toJSON(); - }); - } - remove(organization_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = yield this.exists(organization_id); - if (!exists) { - const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; - err.Details = `Organization '${organization_id}' not found'`; - throw err; - } - yield this.model.findByIdAndRemove(organization_id); - }); - } - exists(organization_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = (yield this.model.exists({ _id: organization_id }).lean().exec()) != - null; - return exists; - }); - } - listAllFromUser(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organizations = yield this.model - .find({ 'members.user': user_id }) - .select('_id name members') - .lean() - .exec(); - return organizations; - }); - } -} -exports.OrganizationService = OrganizationService; diff --git a/build/organizations/validationOrgDb.d.ts b/build/organizations/validationOrgDb.d.ts deleted file mode 100644 index 3904440..0000000 --- a/build/organizations/validationOrgDb.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function createOrganizationCollectionWithValidation(uri: string, databaseName: string, collection_organizations: string): Promise; diff --git a/build/organizations/validationOrgDb.js b/build/organizations/validationOrgDb.js deleted file mode 100644 index 09b565b..0000000 --- a/build/organizations/validationOrgDb.js +++ /dev/null @@ -1,82 +0,0 @@ -"use strict"; -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.createOrganizationCollectionWithValidation = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -const mongodb_1 = require("mongodb"); -dotenv_1.default.config(); -function createOrganizationCollectionWithValidation(uri, databaseName, collection_organizations) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(uri); - yield client.connect(); - const db = client.db(databaseName); - const colecao = db.collection(collection_organizations); - const validationRules = { - validator: { - $jsonSchema: { - bsonType: 'object', - required: ['_id', 'memberLimit', 'name', 'type', 'members'], - properties: { - _id: { - bsonType: 'string', - description: '_id must be a string and is required.', - }, - memberLimit: { - bsonType: 'number', - description: 'memberLimit must be a number and is required.', - }, - name: { - bsonType: 'string', - description: 'name must be a string and is required.', - }, - type: { - bsonType: 'string', - description: 'type must be a string and is required.', - }, - members: { - bsonType: 'array', - description: 'members must be an array and is required.', - items: { - bsonType: 'object', - required: ['user', 'role'], - properties: { - user: { - bsonType: 'string', - description: 'user must be a string and is required.', - }, - role: { - bsonType: 'string', - description: 'role must be a string and is required.', - }, - }, - }, - }, - }, - }, - }, - validationLevel: 'strict', - validationAction: 'error', - }; - yield colecao.createIndex({ user: 1 }); - yield db.command({ - collMod: collection_organizations, - validator: validationRules.validator, - validationLevel: validationRules.validationLevel, - validationAction: validationRules.validationAction, - }); - console.log(`Collection ${collection_organizations} with validation rules created successfully.`); - yield client.close(); - }); -} -exports.createOrganizationCollectionWithValidation = createOrganizationCollectionWithValidation; diff --git a/build/organizations/validationOrgModel.d.ts b/build/organizations/validationOrgModel.d.ts deleted file mode 100644 index 3904cf6..0000000 --- a/build/organizations/validationOrgModel.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IOrganizationDb } from '../interfaces'; -export declare const organizationModel: import("mongoose").Model & IOrganizationDb & Required<{ - _id: string; -}>, any>; diff --git a/build/organizations/validationOrgModel.js b/build/organizations/validationOrgModel.js deleted file mode 100644 index f89227c..0000000 --- a/build/organizations/validationOrgModel.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.organizationModel = void 0; -const mongoose_1 = require("mongoose"); -const organizationSchema = new mongoose_1.Schema({ - _id: { type: String, required: true }, - memberLimit: { type: Number, required: true }, - name: { type: String, required: true }, - type: { type: String, required: true }, - members: [ - { - _id: false, - user: { type: String, required: true, index: true }, - role: { type: String, required: true }, - }, - ], -}); -exports.organizationModel = (0, mongoose_1.model)('organization', organizationSchema); diff --git a/build/projects/services/ProjectService.d.ts b/build/projects/services/ProjectService.d.ts deleted file mode 100644 index 64fd378..0000000 --- a/build/projects/services/ProjectService.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IProjectDb } from '../../interfaces'; -export declare class ProjectService { - protected model: import("mongoose").Model & IProjectDb & Required<{ - _id: string; - }>, any>; - protected configure(): void; - insert(project: IProjectDb): Promise; - get(project_id: string, user_id: string): Promise; - getPopulated(project_id: string, user_id: string): Promise; - update(project: IProjectDb): Promise; - remove(project_id: string, user_id: string): Promise; - removeAllFromUser(user_id: string): Promise; - exists(project_id: string, user_id: string): Promise; - existsWithName(user_id: string, project_name: string): Promise; - listAllFromUser(user_id: string): Promise; - listAllFromUserPopulated(user_id: string): Promise; - listAll(): Promise; -} diff --git a/build/projects/services/ProjectService.js b/build/projects/services/ProjectService.js deleted file mode 100644 index 1616183..0000000 --- a/build/projects/services/ProjectService.js +++ /dev/null @@ -1,156 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ProjectService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const validationProjectsModel_1 = require("../validationProjectsModel"); -const connection_1 = require("../../connection"); -class ProjectService { - constructor() { - this.model = validationProjectsModel_1.projectModel; - } - configure() { } - insert(project) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project_record = new this.model(project); - yield project_record.save(); - return project_record.toJSON(); - }); - } - get(project_id, user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project_record = yield this.model - .findOne({ _id: project_id, user_id: user_id }) - .lean() - .exec(); - if (!project_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; - err.Details = `Project '${project_id}' not found'`; - throw err; - } - return project_record; - }); - } - getPopulated(project_id, user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project_record = yield this.model - .findOne({ _id: project_id, user_id: user_id }) - .populate('clouds') - .populate('bim') - .populate('images') - .lean() - .exec(); - if (!project_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; - err.Details = `Project '${project_id}' not found'`; - throw err; - } - return project_record; - }); - } - update(project) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project_record = yield this.model.findByIdAndUpdate(project._id, project, { - new: true, - }); - if (!project_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; - err.Details = `Project '${project._id}' not found'`; - throw err; - } - return project_record.toJSON(); - }); - } - remove(project_id, user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = yield this.exists(project_id, user_id); - if (!exists) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; - err.Details = `Project '${project_id}' not found'`; - throw err; - } - yield this.model.findByIdAndRemove(project_id); - }); - } - removeAllFromUser(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - yield this.model.deleteMany({ user_id: user_id }); - }); - } - exists(project_id, user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = (yield this.model - .exists({ _id: project_id, user_id: user_id }) - .lean() - .exec()) != null; - return exists; - }); - } - existsWithName(user_id, project_name) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project = yield this.model - .findOne({ user_id: user_id, name: project_name }) - .lean() - .exec(); - return project != null; - }); - } - listAllFromUser(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const projects = yield this.model - .find({ user_id: user_id }) - .lean() - .exec(); - return projects; - }); - } - listAllFromUserPopulated(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const projects = yield this.model - .find({ user_id: user_id }) - .populate('clouds') - .populate('bim') - .populate('images') - .lean() - .exec(); - return projects; - }); - } - listAll() { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const projects = yield this.model.find().lean().exec(); - return projects; - }); - } -} -exports.ProjectService = ProjectService; diff --git a/build/projects/validationProjectsDb.d.ts b/build/projects/validationProjectsDb.d.ts deleted file mode 100644 index 036c18b..0000000 --- a/build/projects/validationProjectsDb.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function createProjectCollectionWithValidation(uri: string, databaseName: string, collection_projects: string): Promise; diff --git a/build/projects/validationProjectsDb.js b/build/projects/validationProjectsDb.js deleted file mode 100644 index f44a3f7..0000000 --- a/build/projects/validationProjectsDb.js +++ /dev/null @@ -1,140 +0,0 @@ -"use strict"; -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.createProjectCollectionWithValidation = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -const mongodb_1 = require("mongodb"); -dotenv_1.default.config(); -function createProjectCollectionWithValidation(uri, databaseName, collection_projects) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(uri); - yield client.connect(); - const db = client.db(databaseName); - const colecao = db.collection(collection_projects); - const validationRules = { - validator: { - $jsonSchema: { - bsonType: 'object', - required: [ - '_id', - 'user_id', - 'name', - 'clientName', - 'type', - 'favorite', - 'clouds', - 'images', - 'bim', - 'projectQuota', - 'createdAt', - 'modifiedAt', - 'publicAccessToken', - 'status', - ], - properties: { - _id: { - bsonType: 'string', - description: 'ID do projeto (string)', - }, - user_id: { - bsonType: 'string', - description: 'ID do usuário (string)', - }, - name: { - bsonType: 'string', - description: 'Nome do projeto (string)', - }, - clientName: { - bsonType: 'string', - description: 'Nome do cliente (string)', - }, - type: { - bsonType: 'string', - description: 'Tipo do projeto (string)', - }, - favorite: { - bsonType: 'bool', - description: 'Indicador de favorito (boolean)', - }, - clouds: { - bsonType: 'array', - items: { bsonType: 'string' }, - description: 'Lista de nuvens associadas (array de strings)', - }, - images: { - bsonType: 'array', - items: { bsonType: 'string' }, - description: 'Lista de imagens associadas (array de strings)', - }, - bim: { - bsonType: 'array', - items: { bsonType: 'string' }, - description: 'Lista de modelos BIM associados (array de strings)', - }, - projectQuota: { - bsonType: 'object', - required: [ - 'pointCloudUsedMB', - 'imageUsedMB', - 'BIMUsedMB', - ], - properties: { - pointCloudUsedMB: { - bsonType: 'number', - description: 'Uso de nuvem de pontos (number)', - }, - imageUsedMB: { - bsonType: 'number', - description: 'Uso de tamanho da imagem (number)', - }, - BIMUsedMB: { - bsonType: 'number', - description: 'Uso de tamanho do BIM (number)', - }, - }, - }, - createdAt: { - bsonType: 'number', - description: 'Timestamp de criação (number)', - }, - modifiedAt: { - bsonType: 'number', - description: 'Timestamp de modificação (number)', - }, - publicAccessToken: { - bsonType: 'string', - description: 'Token de acesso público (string)', - }, - status: { - bsonType: 'string', - description: 'Status do projeto (string)', - }, - }, - }, - }, - validationLevel: 'strict', - validationAction: 'error', - }; - yield colecao.createIndex({ user_id: 1 }); - yield db.command({ - collMod: collection_projects, - validator: validationRules.validator, - validationLevel: validationRules.validationLevel, - validationAction: validationRules.validationAction, - }); - console.log(`Collection ${collection_projects} with validation rules created successfully.`); - yield client.close(); - }); -} -exports.createProjectCollectionWithValidation = createProjectCollectionWithValidation; diff --git a/build/projects/validationProjectsModel.d.ts b/build/projects/validationProjectsModel.d.ts deleted file mode 100644 index e24a0ec..0000000 --- a/build/projects/validationProjectsModel.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IProjectDb } from '../interfaces'; -export declare const projectModel: import("mongoose").Model & IProjectDb & Required<{ - _id: string; -}>, any>; diff --git a/build/projects/validationProjectsModel.js b/build/projects/validationProjectsModel.js deleted file mode 100644 index bbfe911..0000000 --- a/build/projects/validationProjectsModel.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.projectModel = void 0; -const mongoose_1 = require("mongoose"); -const projectSchema = new mongoose_1.Schema({ - _id: { type: String, required: true }, - user_id: { type: String, required: true, index: true }, - name: { type: String, required: true }, - clientName: { type: String, required: true }, - type: { type: String, required: true }, - snapshot: { type: String, required: false }, - favorite: { type: Boolean, required: true }, - clouds: { type: [String], default: [], ref: 'entity' }, - images: { type: [String], default: [], ref: 'entity' }, - bim: { type: [String], default: [], ref: 'entity' }, - projectQuota: { - pointCloudUsedMB: { type: Number, required: true }, - imageUsedMB: { type: Number, required: true }, - BIMUsedMB: { type: Number, required: true }, - }, - createdAt: { type: Number, required: true }, - modifiedAt: { type: Number, required: true }, - owner: { type: String, required: false }, - accessType: { type: String, required: false }, - publicAccessToken: { type: String, required: true }, - status: { type: String, required: true }, -}); -exports.projectModel = (0, mongoose_1.model)('project', projectSchema); diff --git a/build/users/services/createUserService.d.ts b/build/users/services/createUserService.d.ts deleted file mode 100644 index 717b62f..0000000 --- a/build/users/services/createUserService.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { IUsers } from '../../interfaces'; -export declare function createUserService(user: IUsers): Promise; diff --git a/build/users/services/createUserService.js b/build/users/services/createUserService.js deleted file mode 100644 index d964f6b..0000000 --- a/build/users/services/createUserService.js +++ /dev/null @@ -1,60 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.createUserService = void 0; -const validationUserModel_1 = require("../validationUserModel"); -const uuid_1 = require("uuid"); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function createUserService(user) { - return __awaiter(this, void 0, void 0, function* () { - try { - const existingUser = yield validationUserModel_1.UserModel.findOne({ email: user.email }); - if (existingUser) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ResourceExists; - throw err; - } - const newUser = new validationUserModel_1.UserModel({ - _id: (0, uuid_1.v4)(), - name: user.name, - lastName: user.lastName, - email: user.email, - password: user.password, - actingField: user.actingField, - phoneNumber: user.phoneNumber, - postalCode: user.postalCode, - useObjective: user.useObjective, - imagePath: user.imagePath, - street: user.street, - number: user.number, - complement: user.complement, - quota: { - BIMSizeQuotaMB: 5000, - pointCloudQuotaMB: 5000, - imageSizeQuotaMB: 5000, - BIMUsedMB: 0, - imageUsedMB: 0, - pointCloudUsedMB: 0, - }, - customerId: user.customerId - }); - const savedUser = yield newUser.save(); - return savedUser; - } - catch (error) { - if (error !== duna_web_platform_error_defs_1.ErrorMessages.ResourceExists) { - error = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - error.Details = 'Possibly wrong data schema.'; - } - throw error; - } - }); -} -exports.createUserService = createUserService; diff --git a/build/users/services/deleteUserService.d.ts b/build/users/services/deleteUserService.d.ts deleted file mode 100644 index 83f05a5..0000000 --- a/build/users/services/deleteUserService.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -export declare function deleteUserService(userId: string): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ - _id: string; -}>) | null>; diff --git a/build/users/services/deleteUserService.js b/build/users/services/deleteUserService.js deleted file mode 100644 index 097dd49..0000000 --- a/build/users/services/deleteUserService.js +++ /dev/null @@ -1,27 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.deleteUserService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const validationUserModel_1 = require("../validationUserModel"); -function deleteUserService(userId) { - return __awaiter(this, void 0, void 0, function* () { - try { - return yield validationUserModel_1.UserModel.findOneAndDelete({ _id: userId }); - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Internal server Error '; - throw err; - } - }); -} -exports.deleteUserService = deleteUserService; diff --git a/build/users/services/getOneUserService.d.ts b/build/users/services/getOneUserService.d.ts deleted file mode 100644 index 8f7d2e7..0000000 --- a/build/users/services/getOneUserService.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -export declare function getOneUserService(_id: string): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ - _id: string; -}>) | null>; diff --git a/build/users/services/getOneUserService.js b/build/users/services/getOneUserService.js deleted file mode 100644 index 88556cc..0000000 --- a/build/users/services/getOneUserService.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getOneUserService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const validationUserModel_1 = require("../validationUserModel"); -function getOneUserService(_id) { - return __awaiter(this, void 0, void 0, function* () { - try { - const user = yield validationUserModel_1.UserModel.findOne({ _id }); - return user; - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Internal server Error '; - throw err; - } - }); -} -exports.getOneUserService = getOneUserService; diff --git a/build/users/services/getUsersService.d.ts b/build/users/services/getUsersService.d.ts deleted file mode 100644 index 9602c32..0000000 --- a/build/users/services/getUsersService.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -export declare function getUsersService(): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ - _id: string; -}>)[]>; diff --git a/build/users/services/getUsersService.js b/build/users/services/getUsersService.js deleted file mode 100644 index fada50f..0000000 --- a/build/users/services/getUsersService.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getUsersService = void 0; -const validationUserModel_1 = require("../validationUserModel"); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function getUsersService() { - return __awaiter(this, void 0, void 0, function* () { - try { - const user = yield validationUserModel_1.UserModel.find(); - return user; - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Internal server Error '; - throw err; - } - }); -} -exports.getUsersService = getUsersService; diff --git a/build/users/services/loginService.d.ts b/build/users/services/loginService.d.ts deleted file mode 100644 index f30fbd0..0000000 --- a/build/users/services/loginService.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { IUsers } from '../../interfaces'; -export declare function getUserByEmail(email: string): Promise; diff --git a/build/users/services/loginService.js b/build/users/services/loginService.js deleted file mode 100644 index b90a214..0000000 --- a/build/users/services/loginService.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getUserByEmail = void 0; -const validationUserModel_1 = require("../validationUserModel"); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function getUserByEmail(email) { - return __awaiter(this, void 0, void 0, function* () { - try { - const user = yield validationUserModel_1.UserModel.findOne({ email }).exec(); - return user; - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Internal server Error '; - throw err; - } - }); -} -exports.getUserByEmail = getUserByEmail; diff --git a/build/users/services/updateUserService.d.ts b/build/users/services/updateUserService.d.ts deleted file mode 100644 index cc3e1e3..0000000 --- a/build/users/services/updateUserService.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { IUsers } from '../../interfaces'; -export declare function updateUserService(userId: string, updates: Partial): Promise; diff --git a/build/users/services/updateUserService.js b/build/users/services/updateUserService.js deleted file mode 100644 index b284704..0000000 --- a/build/users/services/updateUserService.js +++ /dev/null @@ -1,58 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.updateUserService = void 0; -const validationUserModel_1 = require("../validationUserModel"); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function updateUserService(userId, updates) { - return __awaiter(this, void 0, void 0, function* () { - try { - const existingUser = yield validationUserModel_1.UserModel.findById(userId); - if (!existingUser) { - return null; - } - if (updates.name) - existingUser.name = updates.name; - if (updates.lastName) - existingUser.lastName = updates.lastName; - if (updates.email) - existingUser.email = updates.email; - if (updates.password) - existingUser.password = updates.password; - if (updates.actingField) - existingUser.actingField = updates.actingField; - if (updates.phoneNumber) - existingUser.phoneNumber = updates.phoneNumber; - if (updates.postalCode) - existingUser.postalCode = updates.postalCode; - if (updates.useObjective) - existingUser.useObjective = updates.useObjective; - if (updates.imagePath) - existingUser.imagePath = updates.imagePath; - if (updates.street) - existingUser.street = updates.street; - if (updates.number) - existingUser.number = updates.number; - if (updates.complement) - existingUser.complement = updates.complement; - if (updates.quota) - existingUser.quota = updates.quota; - yield existingUser.save(); - return existingUser; - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Error updating user data.'; - throw err; - } - }); -} -exports.updateUserService = updateUserService; diff --git a/build/users/validationDbUsers.d.ts b/build/users/validationDbUsers.d.ts deleted file mode 100644 index a5d5f32..0000000 --- a/build/users/validationDbUsers.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function createUserCollectionWithValidation(uri: string, databaseName: string, collectionName: string): Promise; diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js deleted file mode 100644 index fe39caf..0000000 --- a/build/users/validationDbUsers.js +++ /dev/null @@ -1,121 +0,0 @@ -"use strict"; -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.createUserCollectionWithValidation = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -const mongodb_1 = require("mongodb"); -dotenv_1.default.config(); -function createUserCollectionWithValidation(uri, databaseName, collectionName) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(uri); - yield client.connect(); - const db = client.db(databaseName); - const colecao = db.collection(collectionName); - const validationRules = { - validator: { - $jsonSchema: { - bsonType: 'object', - required: [ - 'name', - 'lastName', - 'password', - 'postalCode', - 'street', - 'number', - 'quota', - ], - properties: { - name: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - lastName: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - password: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - postalCode: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - street: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - number: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - complement: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - quota: { - bsonType: 'object', - required: [ - 'pointCloudQuotaMB', - 'imageSizeQuotaMB', - 'BIMSizeQuotaMB', - 'pointCloudUsedMB', - 'imageUsedMB', - 'BIMUsedMB', - ], - properties: { - pointCloudQuotaMB: { - bsonType: 'number', - description: 'Quota para nuvem de pontos (number)', - }, - imageSizeQuotaMB: { - bsonType: 'number', - description: 'Quota para tamanho da imagem (number)', - }, - BIMSizeQuotaMB: { - bsonType: 'number', - description: 'Quota para tamanho do BIM (number)', - }, - pointCloudUsedMB: { - bsonType: 'number', - description: 'Uso de nuvem de pontos (number)', - }, - imageUsedMB: { - bsonType: 'number', - description: 'Uso de tamanho da imagem (number)', - }, - BIMUsedMB: { - bsonType: 'number', - description: 'Uso de tamanho do BIM (number)', - }, - }, - }, - }, - }, - }, - validationLevel: 'strict', - validationAction: 'error', - }; - yield colecao.createIndex({ _id: 1 }); - yield db.command({ - collMod: colecao.collectionName, - validator: validationRules.validator, - validationLevel: validationRules.validationLevel, - validationAction: validationRules.validationAction, - }); - console.log(`Coleção ${collectionName} com regras de validação criada com sucesso.`); - yield client.close(); - }); -} -exports.createUserCollectionWithValidation = createUserCollectionWithValidation; diff --git a/build/users/validationUserModel.d.ts b/build/users/validationUserModel.d.ts deleted file mode 100644 index 86c6c19..0000000 --- a/build/users/validationUserModel.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Model } from 'mongoose'; -import { IUsers } from '../interfaces'; -declare const UserModel: Model; -export { UserModel }; diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js deleted file mode 100644 index 2bbca45..0000000 --- a/build/users/validationUserModel.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.UserModel = void 0; -const mongoose_1 = __importDefault(require("mongoose")); -const UserSchema = new mongoose_1.default.Schema({ - _id: { type: String, required: true }, - name: { type: String, required: true }, - lastName: { type: String, required: true }, - email: { type: String, unique: true }, - password: { type: String, required: true }, - actingField: { type: String, default: '' }, - phoneNumber: { type: String, default: '' }, - postalCode: { type: String, required: true, default: '' }, - useObjective: { type: String, default: '' }, - imagePath: { type: String, default: '' }, - street: { type: String, required: true, default: '' }, - number: { type: String, required: true, default: '' }, - complement: { type: String, default: '' }, - quota: { - pointCloudQuotaMB: { type: Number, required: true }, - imageSizeQuotaMB: { type: Number, required: true }, - BIMSizeQuotaMB: { type: Number, required: true }, - pointCloudUsedMB: { type: Number, required: true }, - imageUsedMB: { type: Number, required: true }, - BIMUsedMB: { type: Number, required: true }, - }, - customerId: { type: String, required: false }, - validatedMail: { type: Boolean, required: true, default: false }, -}); -const UserModel = mongoose_1.default.model('user', UserSchema); -exports.UserModel = UserModel; diff --git a/build/usersProject/UserService.d.ts b/build/usersProject/UserService.d.ts deleted file mode 100644 index 3774e0f..0000000 --- a/build/usersProject/UserService.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IUsers } from '../interfaces'; -export declare class UserService { - protected model: import("mongoose").Model & IUsers & Required<{ - _id: string; - }>, any>; - protected configure(): void; - get(user_id?: string, email?: string): Promise; - update(user: IUsers): Promise; -} diff --git a/build/usersProject/UserService.js b/build/usersProject/UserService.js deleted file mode 100644 index ec1a453..0000000 --- a/build/usersProject/UserService.js +++ /dev/null @@ -1,57 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.UserService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const connection_1 = require("../connection"); -const validationUserModel_1 = require("../users/validationUserModel"); -class UserService { - constructor() { - this.model = validationUserModel_1.UserModel; - } - configure() { } - get(user_id, email) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - let user; - if (user_id) { - user = yield this.model.findById(user_id).lean().exec(); - } - else { - user = yield this.model.findOne({ email: email }).lean().exec(); - } - if (!user) { - const id = user_id ? user_id : email; - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = `User ${id} not found`; - throw err; - } - return user; - }); - } - update(user) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const user_record = yield this.model.findByIdAndUpdate(user._id, user, { - new: true, - }); - if (!user_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.UserNotFound; - err.Details = `User '${user._id}' not found'`; - throw err; - } - return user_record.toJSON(); - }); - } -} -exports.UserService = UserService; diff --git a/src/index.ts b/src/index.ts index 03d2192..95dab8e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,7 @@ import { ProjectService } from './projects/services/ProjectService' import { OrganizationService } from './organizations/services/OrganizationService' import { updateUserService } from './users/services/updateUserService' import { UserService } from './usersProject/UserService' +import { updateCustomerId } from './users/services/updateCustomerIdService' export { createUserCollectionWithValidation, @@ -40,6 +41,7 @@ export { createUserService, updateUserService, getUserByEmail, + updateCustomerId, UserService, OrganizationService, EntityService, diff --git a/src/users/services/updateCustomerIdService.ts b/src/users/services/updateCustomerIdService.ts new file mode 100644 index 0000000..18a0460 --- /dev/null +++ b/src/users/services/updateCustomerIdService.ts @@ -0,0 +1,27 @@ +import { ErrorMessages } from "duna-web-platform-error-defs"; +import { IUsers } from "../../interfaces"; +import { UserModel } from "../validationUserModel"; + + +export async function updateCustomerId( + email: string, + updates: Partial + ): Promise { + try { + const existingUser = await UserModel.findOne({ email: email }); + + if (!existingUser) { + return null; + } + if(updates.customerId) existingUser.customerId = updates.customerId + + await existingUser.save(); + + return existingUser; + } catch (error) { + console.error('Error in updateUserService:', error); + const err = ErrorMessages.InternalServerError; + err.Details = 'Error updating user data.'; + throw err; + } + } \ No newline at end of file From b176827ce44b3e0b01db3578d5bd0cfeb149d39c Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Sat, 13 Jan 2024 12:55:04 -0300 Subject: [PATCH 04/20] feat:build --- build/connection.d.ts | 3 + build/connection.js | 50 +++++ build/entity/services/EntityService.d.ts | 58 ++++++ build/entity/services/EntityService.js | 173 ++++++++++++++++++ build/entity/validationEntityDb.d.ts | 1 + build/entity/validationEntityDb.js | 83 +++++++++ build/entity/validationEntityModel.d.ts | 29 +++ build/entity/validationEntityModel.js | 15 ++ build/index.d.ts | 25 +++ build/index.js | 45 +++++ build/interfaces.d.ts | 109 +++++++++++ build/interfaces.js | 32 ++++ .../services/OrganizationService.d.ts | 39 ++++ .../services/OrganizationService.js | 118 ++++++++++++ build/organizations/validationOrgDb.d.ts | 1 + build/organizations/validationOrgDb.js | 82 +++++++++ build/organizations/validationOrgModel.d.ts | 29 +++ build/organizations/validationOrgModel.js | 18 ++ build/projects/services/ProjectService.d.ts | 43 +++++ build/projects/services/ProjectService.js | 156 ++++++++++++++++ build/projects/validationProjectsDb.d.ts | 1 + build/projects/validationProjectsDb.js | 140 ++++++++++++++ build/projects/validationProjectsModel.d.ts | 29 +++ build/projects/validationProjectsModel.js | 28 +++ build/users/services/createUserService.d.ts | 2 + build/users/services/createUserService.js | 60 ++++++ build/users/services/deleteUserService.d.ts | 28 +++ build/users/services/deleteUserService.js | 27 +++ build/users/services/getOneUserService.d.ts | 28 +++ build/users/services/getOneUserService.js | 28 +++ build/users/services/getUsersService.d.ts | 28 +++ build/users/services/getUsersService.js | 28 +++ build/users/services/loginService.d.ts | 2 + build/users/services/loginService.js | 28 +++ .../services/updateCustomerIdService.d.ts | 2 + .../users/services/updateCustomerIdService.js | 35 ++++ build/users/services/updateUserService.d.ts | 2 + build/users/services/updateUserService.js | 58 ++++++ build/users/validationDbUsers.d.ts | 1 + build/users/validationDbUsers.js | 121 ++++++++++++ build/users/validationUserModel.d.ts | 4 + build/users/validationUserModel.js | 34 ++++ build/usersProject/UserService.d.ts | 34 ++++ build/usersProject/UserService.js | 57 ++++++ 44 files changed, 1914 insertions(+) create mode 100644 build/connection.d.ts create mode 100644 build/connection.js create mode 100644 build/entity/services/EntityService.d.ts create mode 100644 build/entity/services/EntityService.js create mode 100644 build/entity/validationEntityDb.d.ts create mode 100644 build/entity/validationEntityDb.js create mode 100644 build/entity/validationEntityModel.d.ts create mode 100644 build/entity/validationEntityModel.js create mode 100644 build/index.d.ts create mode 100644 build/index.js create mode 100644 build/interfaces.d.ts create mode 100644 build/interfaces.js create mode 100644 build/organizations/services/OrganizationService.d.ts create mode 100644 build/organizations/services/OrganizationService.js create mode 100644 build/organizations/validationOrgDb.d.ts create mode 100644 build/organizations/validationOrgDb.js create mode 100644 build/organizations/validationOrgModel.d.ts create mode 100644 build/organizations/validationOrgModel.js create mode 100644 build/projects/services/ProjectService.d.ts create mode 100644 build/projects/services/ProjectService.js create mode 100644 build/projects/validationProjectsDb.d.ts create mode 100644 build/projects/validationProjectsDb.js create mode 100644 build/projects/validationProjectsModel.d.ts create mode 100644 build/projects/validationProjectsModel.js create mode 100644 build/users/services/createUserService.d.ts create mode 100644 build/users/services/createUserService.js create mode 100644 build/users/services/deleteUserService.d.ts create mode 100644 build/users/services/deleteUserService.js create mode 100644 build/users/services/getOneUserService.d.ts create mode 100644 build/users/services/getOneUserService.js create mode 100644 build/users/services/getUsersService.d.ts create mode 100644 build/users/services/getUsersService.js create mode 100644 build/users/services/loginService.d.ts create mode 100644 build/users/services/loginService.js create mode 100644 build/users/services/updateCustomerIdService.d.ts create mode 100644 build/users/services/updateCustomerIdService.js create mode 100644 build/users/services/updateUserService.d.ts create mode 100644 build/users/services/updateUserService.js create mode 100644 build/users/validationDbUsers.d.ts create mode 100644 build/users/validationDbUsers.js create mode 100644 build/users/validationUserModel.d.ts create mode 100644 build/users/validationUserModel.js create mode 100644 build/usersProject/UserService.d.ts create mode 100644 build/usersProject/UserService.js diff --git a/build/connection.d.ts b/build/connection.d.ts new file mode 100644 index 0000000..5edda3e --- /dev/null +++ b/build/connection.d.ts @@ -0,0 +1,3 @@ +export declare function connectToDatabase(url: string, databaseName: string): Promise; +export declare function checkConnectionStatus(): void; +export declare function subscribeToDatabaseEvents(): void; diff --git a/build/connection.js b/build/connection.js new file mode 100644 index 0000000..560ad28 --- /dev/null +++ b/build/connection.js @@ -0,0 +1,50 @@ +"use strict"; +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.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = void 0; +const mongoose_1 = __importDefault(require("mongoose")); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function connectToDatabase(url, databaseName) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield mongoose_1.default.connect(`${url}/${databaseName}`, {}); + console.log(`Conectado ao banco de dados: ${databaseName}`); + } + catch (error) { + throw error; + } + }); +} +exports.connectToDatabase = connectToDatabase; +function checkConnectionStatus() { + // 1 -> Connected + if (mongoose_1.default.connection.readyState != 1) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = `MongoDB disconnected`; + throw err; + } +} +exports.checkConnectionStatus = checkConnectionStatus; +function subscribeToDatabaseEvents() { + mongoose_1.default.connection.on('connected', () => { + console.log(`⚡️[database]: MongoDB connected`); + }); + mongoose_1.default.connection.on('error', (error) => { + console.log(`⚡️[database]: MongoDB Error - ${error}`); + }); + mongoose_1.default.connection.on('disconnected', () => { + console.log(`⚡️[database]: MongoDB Disconnected`); + }); +} +exports.subscribeToDatabaseEvents = subscribeToDatabaseEvents; diff --git a/build/entity/services/EntityService.d.ts b/build/entity/services/EntityService.d.ts new file mode 100644 index 0000000..1cfec63 --- /dev/null +++ b/build/entity/services/EntityService.d.ts @@ -0,0 +1,58 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IEntityDb } from '../../interfaces'; +export declare class EntityService { + protected model: import("mongoose").Model & IEntityDb & Required<{ + _id: string; + }>, any>; + protected configure(): void; + insert(entity: IEntityDb): Promise; + get(entity_id: string): Promise; + getByName(project_id: string, entity_name: string): Promise; + update(entity: IEntityDb): Promise; + remove(entity_id: string): Promise; + removeAllFromUser(user_id: string): Promise; + exists(entity_id: string): Promise; + existsWithName(project_id: string, entity_name: string): Promise; + listAllFromProject(project_id: string): Promise; + /** + * Assign a parent entity to another entity. This essentially + * makes them a `child` entity. Child entities are not allowed + * to be processed. (business logic) + * + * @param project_id + * @param entity_name + * @param parent_entity_name + */ + assignParentName(project_id: string, entity_name: string, parent_entity_name: string): Promise; + /** + * Promote entity. Removes the parent field and allows them to be processed + * (business logic) + * @param project_id + * @param entity_name + */ + promoteEntity(project_id: string, entity_name: string): Promise; +} diff --git a/build/entity/services/EntityService.js b/build/entity/services/EntityService.js new file mode 100644 index 0000000..1e4da80 --- /dev/null +++ b/build/entity/services/EntityService.js @@ -0,0 +1,173 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.EntityService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const connection_1 = require("../../connection"); +const validationEntityModel_1 = require("../validationEntityModel"); +class EntityService { + constructor() { + this.model = validationEntityModel_1.entityModel; + } + configure() { } + insert(entity) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entity_record = new this.model(entity); + yield entity_record.save(); + return entity_record.toJSON(); + }); + } + get(entity_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entity_record = yield this.model.findById(entity_id).lean().exec(); + if (!entity_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + throw err; + } + return entity_record; + }); + } + getByName(project_id, entity_name) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entity_record = yield this.model + .findOne({ projectId: project_id, name: entity_name }) + .lean() + .exec(); + if (!entity_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + throw err; + } + return entity_record; + }); + } + update(entity) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entity_record = yield this.model + .findByIdAndUpdate(entity._id, entity, { + new: true, + }) + .lean() + .exec(); + if (!entity_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + throw err; + } + return entity_record; + }); + } + remove(entity_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = yield this.exists(entity_id); + if (!exists) { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + throw err; + } + yield this.model.findByIdAndRemove(entity_id); + }); + } + removeAllFromUser(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + yield this.model.deleteMany({ user_id: user_id }); + }); + } + exists(entity_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = (yield this.model.exists({ _id: entity_id }).lean().exec()) != null; + return exists; + }); + } + existsWithName(project_id, entity_name) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project = yield this.model + .findOne({ projectId: project_id, name: entity_name }) + .lean() + .exec(); + return project != null; + }); + } + listAllFromProject(project_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entities = yield this.model + .find({ proje: project_id }) + .lean() + .exec(); + return entities; + }); + } + /** + * Assign a parent entity to another entity. This essentially + * makes them a `child` entity. Child entities are not allowed + * to be processed. (business logic) + * + * @param project_id + * @param entity_name + * @param parent_entity_name + */ + assignParentName(project_id, entity_name, parent_entity_name) { + return __awaiter(this, void 0, void 0, function* () { + // Check if entity exist. + const child_entity = yield this.getByName(project_id, entity_name); + if (!(yield this.existsWithName(project_id, parent_entity_name))) { + { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + err.Details = `Parent Name: ${parent_entity_name}`; + throw err; + } + } + child_entity.parentName = parent_entity_name; + this.update(child_entity); + }); + } + /** + * Promote entity. Removes the parent field and allows them to be processed + * (business logic) + * @param project_id + * @param entity_name + */ + promoteEntity(project_id, entity_name) { + return __awaiter(this, void 0, void 0, function* () { + // Check if entity exist. + const child_entity = yield this.getByName(project_id, entity_name); + if (child_entity.parentName === undefined) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = + 'Entity is not a chilld, or does not have parent property.'; + throw err; + } + const entity = yield this.model.findOne({ + projectId: project_id, + name: entity_name, + }); + // Assigning document properties to undefined removes them. + entity.parentName = undefined; + yield entity.save(); + }); + } +} +exports.EntityService = EntityService; diff --git a/build/entity/validationEntityDb.d.ts b/build/entity/validationEntityDb.d.ts new file mode 100644 index 0000000..666cb38 --- /dev/null +++ b/build/entity/validationEntityDb.d.ts @@ -0,0 +1 @@ +export declare function createEntityCollectionWithValidation(uri: string, databaseName: string, collectionName: string): Promise; diff --git a/build/entity/validationEntityDb.js b/build/entity/validationEntityDb.js new file mode 100644 index 0000000..04c8ee6 --- /dev/null +++ b/build/entity/validationEntityDb.js @@ -0,0 +1,83 @@ +"use strict"; +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.createEntityCollectionWithValidation = void 0; +const dotenv_1 = __importDefault(require("dotenv")); +const mongodb_1 = require("mongodb"); +dotenv_1.default.config(); +function createEntityCollectionWithValidation(uri, databaseName, collectionName) { + return __awaiter(this, void 0, void 0, function* () { + const client = new mongodb_1.MongoClient(uri); + yield client.connect(); + const db = client.db(databaseName); + const colecao = db.collection(collectionName); + const validationRules = { + validator: { + $jsonSchema: { + bsonType: 'object', + required: [ + 'projectId', + 'type', + 'name', + 'location', + 'sizeMB', + 'shareGroup', + ], + properties: { + projectId: { + bsonType: 'string', + description: 'Project ID must be a string and is required.', + }, + type: { + bsonType: 'string', + description: 'Type must be a string and is required.', + }, + name: { + bsonType: 'string', + description: 'Name must be a string and is required.', + }, + location: { + bsonType: 'string', + description: 'Location must be a string and is required.', + }, + sizeMB: { + bsonType: 'number', + description: 'SizeMB must be a number and is required.', + }, + shareGroup: { + bsonType: 'string', + description: 'Share group must be a string and is required.', + }, + parentName: { + bsonType: 'string', + description: 'Holds a name reference to a parent entity. Not required.', + }, + }, + }, + }, + validationLevel: 'strict', + validationAction: 'error', + }; + yield colecao.createIndex({ projectId: 1 }); + yield db.command({ + collMod: colecao.collectionName, + validator: validationRules.validator, + validationLevel: validationRules.validationLevel, + validationAction: validationRules.validationAction, + }); + console.log(`Collection ${collectionName} with validation rules created successfully.`); + yield client.close(); + }); +} +exports.createEntityCollectionWithValidation = createEntityCollectionWithValidation; diff --git a/build/entity/validationEntityModel.d.ts b/build/entity/validationEntityModel.d.ts new file mode 100644 index 0000000..1a56a9c --- /dev/null +++ b/build/entity/validationEntityModel.d.ts @@ -0,0 +1,29 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IEntityDb } from '../interfaces'; +export declare const entityModel: import("mongoose").Model & IEntityDb & Required<{ + _id: string; +}>, any>; diff --git a/build/entity/validationEntityModel.js b/build/entity/validationEntityModel.js new file mode 100644 index 0000000..ee39e35 --- /dev/null +++ b/build/entity/validationEntityModel.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.entityModel = void 0; +const mongoose_1 = require("mongoose"); +const entitySchema = new mongoose_1.Schema({ + _id: { type: String, required: true }, + projectId: { type: String, required: true, index: true }, + type: { type: String, required: true }, + name: { type: String, required: true }, + location: { type: String, required: true }, + sizeMB: { type: Number, required: true }, + shareGroup: { type: String, required: true }, + parentName: { type: String, requred: false }, +}); +exports.entityModel = (0, mongoose_1.model)('entity', entitySchema); diff --git a/build/index.d.ts b/build/index.d.ts new file mode 100644 index 0000000..c25ed8e --- /dev/null +++ b/build/index.d.ts @@ -0,0 +1,25 @@ +import { createUserCollectionWithValidation } from './users/validationDbUsers'; +import { UserModel } from './users/validationUserModel'; +import { IMemberDb, IUser, IUsers } from './interfaces'; +import { connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents } from './connection'; +import { IEntityDb } from './interfaces'; +import { IProjectDb } from './interfaces'; +import { IOrganizationDb } from './interfaces'; +import { entityModel } from './entity/validationEntityModel'; +import { projectModel } from './projects/validationProjectsModel'; +import { organizationModel } from './organizations/validationOrgModel'; +import { createEntityCollectionWithValidation } from './entity/validationEntityDb'; +import { createProjectCollectionWithValidation } from './projects/validationProjectsDb'; +import { createOrganizationCollectionWithValidation } from './organizations/validationOrgDb'; +import { createUserService } from './users/services/createUserService'; +import { getUserByEmail } from './users/services/loginService'; +import { deleteUserService } from './users/services/deleteUserService'; +import { getOneUserService } from './users/services/getOneUserService'; +import { getUsersService } from './users/services/getUsersService'; +import { EntityService } from './entity/services/EntityService'; +import { ProjectService } from './projects/services/ProjectService'; +import { OrganizationService } from './organizations/services/OrganizationService'; +import { updateUserService } from './users/services/updateUserService'; +import { UserService } from './usersProject/UserService'; +import { updateCustomerId } from './users/services/updateCustomerIdService'; +export { createUserCollectionWithValidation, connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents, createEntityCollectionWithValidation, createProjectCollectionWithValidation, createOrganizationCollectionWithValidation, deleteUserService, getOneUserService, getUsersService, createUserService, updateUserService, getUserByEmail, updateCustomerId, UserService, OrganizationService, EntityService, ProjectService, UserModel, entityModel, organizationModel, IUsers, IUser, IEntityDb, IProjectDb, projectModel, IOrganizationDb, IMemberDb, }; diff --git a/build/index.js b/build/index.js new file mode 100644 index 0000000..ac81097 --- /dev/null +++ b/build/index.js @@ -0,0 +1,45 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.projectModel = exports.organizationModel = exports.entityModel = exports.UserModel = exports.ProjectService = exports.EntityService = exports.OrganizationService = exports.UserService = exports.updateCustomerId = exports.getUserByEmail = exports.updateUserService = exports.createUserService = exports.getUsersService = exports.getOneUserService = exports.deleteUserService = exports.createOrganizationCollectionWithValidation = exports.createProjectCollectionWithValidation = exports.createEntityCollectionWithValidation = exports.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = exports.createUserCollectionWithValidation = void 0; +const validationDbUsers_1 = require("./users/validationDbUsers"); +Object.defineProperty(exports, "createUserCollectionWithValidation", { enumerable: true, get: function () { return validationDbUsers_1.createUserCollectionWithValidation; } }); +const validationUserModel_1 = require("./users/validationUserModel"); +Object.defineProperty(exports, "UserModel", { enumerable: true, get: function () { return validationUserModel_1.UserModel; } }); +const connection_1 = require("./connection"); +Object.defineProperty(exports, "connectToDatabase", { enumerable: true, get: function () { return connection_1.connectToDatabase; } }); +Object.defineProperty(exports, "checkConnectionStatus", { enumerable: true, get: function () { return connection_1.checkConnectionStatus; } }); +Object.defineProperty(exports, "subscribeToDatabaseEvents", { enumerable: true, get: function () { return connection_1.subscribeToDatabaseEvents; } }); +const validationEntityModel_1 = require("./entity/validationEntityModel"); +Object.defineProperty(exports, "entityModel", { enumerable: true, get: function () { return validationEntityModel_1.entityModel; } }); +const validationProjectsModel_1 = require("./projects/validationProjectsModel"); +Object.defineProperty(exports, "projectModel", { enumerable: true, get: function () { return validationProjectsModel_1.projectModel; } }); +const validationOrgModel_1 = require("./organizations/validationOrgModel"); +Object.defineProperty(exports, "organizationModel", { enumerable: true, get: function () { return validationOrgModel_1.organizationModel; } }); +const validationEntityDb_1 = require("./entity/validationEntityDb"); +Object.defineProperty(exports, "createEntityCollectionWithValidation", { enumerable: true, get: function () { return validationEntityDb_1.createEntityCollectionWithValidation; } }); +const validationProjectsDb_1 = require("./projects/validationProjectsDb"); +Object.defineProperty(exports, "createProjectCollectionWithValidation", { enumerable: true, get: function () { return validationProjectsDb_1.createProjectCollectionWithValidation; } }); +const validationOrgDb_1 = require("./organizations/validationOrgDb"); +Object.defineProperty(exports, "createOrganizationCollectionWithValidation", { enumerable: true, get: function () { return validationOrgDb_1.createOrganizationCollectionWithValidation; } }); +const createUserService_1 = require("./users/services/createUserService"); +Object.defineProperty(exports, "createUserService", { enumerable: true, get: function () { return createUserService_1.createUserService; } }); +const loginService_1 = require("./users/services/loginService"); +Object.defineProperty(exports, "getUserByEmail", { enumerable: true, get: function () { return loginService_1.getUserByEmail; } }); +const deleteUserService_1 = require("./users/services/deleteUserService"); +Object.defineProperty(exports, "deleteUserService", { enumerable: true, get: function () { return deleteUserService_1.deleteUserService; } }); +const getOneUserService_1 = require("./users/services/getOneUserService"); +Object.defineProperty(exports, "getOneUserService", { enumerable: true, get: function () { return getOneUserService_1.getOneUserService; } }); +const getUsersService_1 = require("./users/services/getUsersService"); +Object.defineProperty(exports, "getUsersService", { enumerable: true, get: function () { return getUsersService_1.getUsersService; } }); +const EntityService_1 = require("./entity/services/EntityService"); +Object.defineProperty(exports, "EntityService", { enumerable: true, get: function () { return EntityService_1.EntityService; } }); +const ProjectService_1 = require("./projects/services/ProjectService"); +Object.defineProperty(exports, "ProjectService", { enumerable: true, get: function () { return ProjectService_1.ProjectService; } }); +const OrganizationService_1 = require("./organizations/services/OrganizationService"); +Object.defineProperty(exports, "OrganizationService", { enumerable: true, get: function () { return OrganizationService_1.OrganizationService; } }); +const updateUserService_1 = require("./users/services/updateUserService"); +Object.defineProperty(exports, "updateUserService", { enumerable: true, get: function () { return updateUserService_1.updateUserService; } }); +const UserService_1 = require("./usersProject/UserService"); +Object.defineProperty(exports, "UserService", { enumerable: true, get: function () { return UserService_1.UserService; } }); +const updateCustomerIdService_1 = require("./users/services/updateCustomerIdService"); +Object.defineProperty(exports, "updateCustomerId", { enumerable: true, get: function () { return updateCustomerIdService_1.updateCustomerId; } }); diff --git a/build/interfaces.d.ts b/build/interfaces.d.ts new file mode 100644 index 0000000..8dc7412 --- /dev/null +++ b/build/interfaces.d.ts @@ -0,0 +1,109 @@ +export interface IUsers { + _id: string; + name: string; + lastName: string; + email: string; + password: string; + actingField: string; + phoneNumber: string; + postalCode: string; + useObjective: string; + imagePath: string; + cep: string; + street: string; + number: string; + complement: string; + quota: UserQuota; + validatedMail: boolean; + customerId: string; + [key: string]: any; +} +export interface IEntityDb { + _id: string; + projectId: string; + type: EntityType; + name: string; + location: string; + sizeMB: number; + shareGroup: ShareGroupType; + parentName?: string; +} +/** + * Project level quota. Contains summed up entity sized. + */ +export interface ProjectQuota { + pointCloudUsedMB: number; + imageUsedMB: number; + BIMUsedMB: number; +} +/** + * User level quota. Contains quota and used space from all projects. + */ +export interface UserQuota { + pointCloudQuotaMB: number; + imageSizeQuotaMB: number; + BIMSizeQuotaMB: number; + pointCloudUsedMB: number; + imageUsedMB: number; + BIMUsedMB: number; +} +export interface IProjectDb { + _id: string; + user_id: string; + name: string; + clientName: string; + type: string; + snapshot?: string; + favorite: boolean; + clouds: Array; + images: Array; + bim: Array; + projectQuota: ProjectQuota; + createdAt: number; + modifiedAt: number; + publicAccessToken: string; + status: ProjectStatus; + owner?: string; + accessType?: ProjectAccessType; +} +export interface IOrganizationDb { + _id: string; + memberLimit: number; + members: Array; + name: string; + type: string; +} +export interface IMemberDb { + user: string; + role: OrganizationMemberRole; +} +export interface IUser { + _id: string; + name: string; + lastName: string; + email: string; +} +export declare enum OrganizationMemberRole { + VIEWER = "VIEWER", + EDITOR = "EDITOR", + ADMIN = "ADMIN", + OWNER = "OWNER" +} +export declare enum ProjectStatus { + IN_PROGRESS = "IN_PROGRESS", + FINISHED = "FINISHED" +} +export declare enum ProjectAccessType { + INTERNAL = "INTERNAL", + PRIVATE = "PRIVATE" +} +export declare enum ShareGroupType { + Public = "public", + Private = "private" +} +export declare enum EntityType { + PointCloud = "clouds", + Image = "images", + BIM = "bim", + Unknown = "unknown" +} diff --git a/build/interfaces.js b/build/interfaces.js new file mode 100644 index 0000000..21cd19e --- /dev/null +++ b/build/interfaces.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.EntityType = exports.ShareGroupType = exports.ProjectAccessType = exports.ProjectStatus = exports.OrganizationMemberRole = void 0; +var OrganizationMemberRole; +(function (OrganizationMemberRole) { + OrganizationMemberRole["VIEWER"] = "VIEWER"; + OrganizationMemberRole["EDITOR"] = "EDITOR"; + OrganizationMemberRole["ADMIN"] = "ADMIN"; + OrganizationMemberRole["OWNER"] = "OWNER"; +})(OrganizationMemberRole || (exports.OrganizationMemberRole = OrganizationMemberRole = {})); +var ProjectStatus; +(function (ProjectStatus) { + ProjectStatus["IN_PROGRESS"] = "IN_PROGRESS"; + ProjectStatus["FINISHED"] = "FINISHED"; +})(ProjectStatus || (exports.ProjectStatus = ProjectStatus = {})); +var ProjectAccessType; +(function (ProjectAccessType) { + ProjectAccessType["INTERNAL"] = "INTERNAL"; + ProjectAccessType["PRIVATE"] = "PRIVATE"; +})(ProjectAccessType || (exports.ProjectAccessType = ProjectAccessType = {})); +var ShareGroupType; +(function (ShareGroupType) { + ShareGroupType["Public"] = "public"; + ShareGroupType["Private"] = "private"; +})(ShareGroupType || (exports.ShareGroupType = ShareGroupType = {})); +var EntityType; +(function (EntityType) { + EntityType["PointCloud"] = "clouds"; + EntityType["Image"] = "images"; + EntityType["BIM"] = "bim"; + EntityType["Unknown"] = "unknown"; +})(EntityType || (exports.EntityType = EntityType = {})); diff --git a/build/organizations/services/OrganizationService.d.ts b/build/organizations/services/OrganizationService.d.ts new file mode 100644 index 0000000..afa244a --- /dev/null +++ b/build/organizations/services/OrganizationService.d.ts @@ -0,0 +1,39 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IOrganizationDb } from '../../interfaces'; +export declare class OrganizationService { + protected model: import("mongoose").Model & IOrganizationDb & Required<{ + _id: string; + }>, any>; + protected configure(): void; + insert(organization: IOrganizationDb): Promise; + get(organization_id: string): Promise; + getPopulated(organization_id: string): Promise; + update(organization: IOrganizationDb): Promise; + remove(organization_id: string): Promise; + exists(organization_id: string): Promise; + listAllFromUser(user_id: string): Promise>; +} diff --git a/build/organizations/services/OrganizationService.js b/build/organizations/services/OrganizationService.js new file mode 100644 index 0000000..daa61a6 --- /dev/null +++ b/build/organizations/services/OrganizationService.js @@ -0,0 +1,118 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.OrganizationService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const connection_1 = require("../../connection"); +const validationOrgModel_1 = require("../validationOrgModel"); +const validationUserModel_1 = require("../../users/validationUserModel"); +class OrganizationService { + constructor() { + this.model = validationOrgModel_1.organizationModel; + } + configure() { } + insert(organization) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organization_record = new this.model(organization); + yield organization_record.save(); + return organization_record.toJSON(); + }); + } + get(organization_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organization_record = yield this.model + .findById(organization_id) + .lean() + .exec(); + if (!organization_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; + err.Details = `Organization '${organization_id}' not found'`; + throw err; + } + return organization_record; + }); + } + getPopulated(organization_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organization_record = yield this.model + .findById(organization_id) + .populate({ + path: 'members.user', + model: validationUserModel_1.UserModel, + select: '_id name lastName email', + }) + .lean() + .exec(); + if (!organization_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; + err.Details = `Organization '${organization_id}' not found'`; + throw err; + } + return organization_record; + }); + } + update(organization) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organization_record = yield this.model.findByIdAndUpdate(organization._id, organization, { + new: true, + }); + if (!organization_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; + err.Details = `Organization '${organization._id}' not found'`; + throw err; + } + return organization_record.toJSON(); + }); + } + remove(organization_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = yield this.exists(organization_id); + if (!exists) { + const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; + err.Details = `Organization '${organization_id}' not found'`; + throw err; + } + yield this.model.findByIdAndRemove(organization_id); + }); + } + exists(organization_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = (yield this.model.exists({ _id: organization_id }).lean().exec()) != + null; + return exists; + }); + } + listAllFromUser(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organizations = yield this.model + .find({ 'members.user': user_id }) + .select('_id name members') + .lean() + .exec(); + return organizations; + }); + } +} +exports.OrganizationService = OrganizationService; diff --git a/build/organizations/validationOrgDb.d.ts b/build/organizations/validationOrgDb.d.ts new file mode 100644 index 0000000..3904440 --- /dev/null +++ b/build/organizations/validationOrgDb.d.ts @@ -0,0 +1 @@ +export declare function createOrganizationCollectionWithValidation(uri: string, databaseName: string, collection_organizations: string): Promise; diff --git a/build/organizations/validationOrgDb.js b/build/organizations/validationOrgDb.js new file mode 100644 index 0000000..09b565b --- /dev/null +++ b/build/organizations/validationOrgDb.js @@ -0,0 +1,82 @@ +"use strict"; +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.createOrganizationCollectionWithValidation = void 0; +const dotenv_1 = __importDefault(require("dotenv")); +const mongodb_1 = require("mongodb"); +dotenv_1.default.config(); +function createOrganizationCollectionWithValidation(uri, databaseName, collection_organizations) { + return __awaiter(this, void 0, void 0, function* () { + const client = new mongodb_1.MongoClient(uri); + yield client.connect(); + const db = client.db(databaseName); + const colecao = db.collection(collection_organizations); + const validationRules = { + validator: { + $jsonSchema: { + bsonType: 'object', + required: ['_id', 'memberLimit', 'name', 'type', 'members'], + properties: { + _id: { + bsonType: 'string', + description: '_id must be a string and is required.', + }, + memberLimit: { + bsonType: 'number', + description: 'memberLimit must be a number and is required.', + }, + name: { + bsonType: 'string', + description: 'name must be a string and is required.', + }, + type: { + bsonType: 'string', + description: 'type must be a string and is required.', + }, + members: { + bsonType: 'array', + description: 'members must be an array and is required.', + items: { + bsonType: 'object', + required: ['user', 'role'], + properties: { + user: { + bsonType: 'string', + description: 'user must be a string and is required.', + }, + role: { + bsonType: 'string', + description: 'role must be a string and is required.', + }, + }, + }, + }, + }, + }, + }, + validationLevel: 'strict', + validationAction: 'error', + }; + yield colecao.createIndex({ user: 1 }); + yield db.command({ + collMod: collection_organizations, + validator: validationRules.validator, + validationLevel: validationRules.validationLevel, + validationAction: validationRules.validationAction, + }); + console.log(`Collection ${collection_organizations} with validation rules created successfully.`); + yield client.close(); + }); +} +exports.createOrganizationCollectionWithValidation = createOrganizationCollectionWithValidation; diff --git a/build/organizations/validationOrgModel.d.ts b/build/organizations/validationOrgModel.d.ts new file mode 100644 index 0000000..3904cf6 --- /dev/null +++ b/build/organizations/validationOrgModel.d.ts @@ -0,0 +1,29 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IOrganizationDb } from '../interfaces'; +export declare const organizationModel: import("mongoose").Model & IOrganizationDb & Required<{ + _id: string; +}>, any>; diff --git a/build/organizations/validationOrgModel.js b/build/organizations/validationOrgModel.js new file mode 100644 index 0000000..f89227c --- /dev/null +++ b/build/organizations/validationOrgModel.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.organizationModel = void 0; +const mongoose_1 = require("mongoose"); +const organizationSchema = new mongoose_1.Schema({ + _id: { type: String, required: true }, + memberLimit: { type: Number, required: true }, + name: { type: String, required: true }, + type: { type: String, required: true }, + members: [ + { + _id: false, + user: { type: String, required: true, index: true }, + role: { type: String, required: true }, + }, + ], +}); +exports.organizationModel = (0, mongoose_1.model)('organization', organizationSchema); diff --git a/build/projects/services/ProjectService.d.ts b/build/projects/services/ProjectService.d.ts new file mode 100644 index 0000000..64fd378 --- /dev/null +++ b/build/projects/services/ProjectService.d.ts @@ -0,0 +1,43 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IProjectDb } from '../../interfaces'; +export declare class ProjectService { + protected model: import("mongoose").Model & IProjectDb & Required<{ + _id: string; + }>, any>; + protected configure(): void; + insert(project: IProjectDb): Promise; + get(project_id: string, user_id: string): Promise; + getPopulated(project_id: string, user_id: string): Promise; + update(project: IProjectDb): Promise; + remove(project_id: string, user_id: string): Promise; + removeAllFromUser(user_id: string): Promise; + exists(project_id: string, user_id: string): Promise; + existsWithName(user_id: string, project_name: string): Promise; + listAllFromUser(user_id: string): Promise; + listAllFromUserPopulated(user_id: string): Promise; + listAll(): Promise; +} diff --git a/build/projects/services/ProjectService.js b/build/projects/services/ProjectService.js new file mode 100644 index 0000000..1616183 --- /dev/null +++ b/build/projects/services/ProjectService.js @@ -0,0 +1,156 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ProjectService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const validationProjectsModel_1 = require("../validationProjectsModel"); +const connection_1 = require("../../connection"); +class ProjectService { + constructor() { + this.model = validationProjectsModel_1.projectModel; + } + configure() { } + insert(project) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project_record = new this.model(project); + yield project_record.save(); + return project_record.toJSON(); + }); + } + get(project_id, user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project_record = yield this.model + .findOne({ _id: project_id, user_id: user_id }) + .lean() + .exec(); + if (!project_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; + err.Details = `Project '${project_id}' not found'`; + throw err; + } + return project_record; + }); + } + getPopulated(project_id, user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project_record = yield this.model + .findOne({ _id: project_id, user_id: user_id }) + .populate('clouds') + .populate('bim') + .populate('images') + .lean() + .exec(); + if (!project_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; + err.Details = `Project '${project_id}' not found'`; + throw err; + } + return project_record; + }); + } + update(project) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project_record = yield this.model.findByIdAndUpdate(project._id, project, { + new: true, + }); + if (!project_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; + err.Details = `Project '${project._id}' not found'`; + throw err; + } + return project_record.toJSON(); + }); + } + remove(project_id, user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = yield this.exists(project_id, user_id); + if (!exists) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; + err.Details = `Project '${project_id}' not found'`; + throw err; + } + yield this.model.findByIdAndRemove(project_id); + }); + } + removeAllFromUser(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + yield this.model.deleteMany({ user_id: user_id }); + }); + } + exists(project_id, user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = (yield this.model + .exists({ _id: project_id, user_id: user_id }) + .lean() + .exec()) != null; + return exists; + }); + } + existsWithName(user_id, project_name) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project = yield this.model + .findOne({ user_id: user_id, name: project_name }) + .lean() + .exec(); + return project != null; + }); + } + listAllFromUser(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const projects = yield this.model + .find({ user_id: user_id }) + .lean() + .exec(); + return projects; + }); + } + listAllFromUserPopulated(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const projects = yield this.model + .find({ user_id: user_id }) + .populate('clouds') + .populate('bim') + .populate('images') + .lean() + .exec(); + return projects; + }); + } + listAll() { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const projects = yield this.model.find().lean().exec(); + return projects; + }); + } +} +exports.ProjectService = ProjectService; diff --git a/build/projects/validationProjectsDb.d.ts b/build/projects/validationProjectsDb.d.ts new file mode 100644 index 0000000..036c18b --- /dev/null +++ b/build/projects/validationProjectsDb.d.ts @@ -0,0 +1 @@ +export declare function createProjectCollectionWithValidation(uri: string, databaseName: string, collection_projects: string): Promise; diff --git a/build/projects/validationProjectsDb.js b/build/projects/validationProjectsDb.js new file mode 100644 index 0000000..f44a3f7 --- /dev/null +++ b/build/projects/validationProjectsDb.js @@ -0,0 +1,140 @@ +"use strict"; +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.createProjectCollectionWithValidation = void 0; +const dotenv_1 = __importDefault(require("dotenv")); +const mongodb_1 = require("mongodb"); +dotenv_1.default.config(); +function createProjectCollectionWithValidation(uri, databaseName, collection_projects) { + return __awaiter(this, void 0, void 0, function* () { + const client = new mongodb_1.MongoClient(uri); + yield client.connect(); + const db = client.db(databaseName); + const colecao = db.collection(collection_projects); + const validationRules = { + validator: { + $jsonSchema: { + bsonType: 'object', + required: [ + '_id', + 'user_id', + 'name', + 'clientName', + 'type', + 'favorite', + 'clouds', + 'images', + 'bim', + 'projectQuota', + 'createdAt', + 'modifiedAt', + 'publicAccessToken', + 'status', + ], + properties: { + _id: { + bsonType: 'string', + description: 'ID do projeto (string)', + }, + user_id: { + bsonType: 'string', + description: 'ID do usuário (string)', + }, + name: { + bsonType: 'string', + description: 'Nome do projeto (string)', + }, + clientName: { + bsonType: 'string', + description: 'Nome do cliente (string)', + }, + type: { + bsonType: 'string', + description: 'Tipo do projeto (string)', + }, + favorite: { + bsonType: 'bool', + description: 'Indicador de favorito (boolean)', + }, + clouds: { + bsonType: 'array', + items: { bsonType: 'string' }, + description: 'Lista de nuvens associadas (array de strings)', + }, + images: { + bsonType: 'array', + items: { bsonType: 'string' }, + description: 'Lista de imagens associadas (array de strings)', + }, + bim: { + bsonType: 'array', + items: { bsonType: 'string' }, + description: 'Lista de modelos BIM associados (array de strings)', + }, + projectQuota: { + bsonType: 'object', + required: [ + 'pointCloudUsedMB', + 'imageUsedMB', + 'BIMUsedMB', + ], + properties: { + pointCloudUsedMB: { + bsonType: 'number', + description: 'Uso de nuvem de pontos (number)', + }, + imageUsedMB: { + bsonType: 'number', + description: 'Uso de tamanho da imagem (number)', + }, + BIMUsedMB: { + bsonType: 'number', + description: 'Uso de tamanho do BIM (number)', + }, + }, + }, + createdAt: { + bsonType: 'number', + description: 'Timestamp de criação (number)', + }, + modifiedAt: { + bsonType: 'number', + description: 'Timestamp de modificação (number)', + }, + publicAccessToken: { + bsonType: 'string', + description: 'Token de acesso público (string)', + }, + status: { + bsonType: 'string', + description: 'Status do projeto (string)', + }, + }, + }, + }, + validationLevel: 'strict', + validationAction: 'error', + }; + yield colecao.createIndex({ user_id: 1 }); + yield db.command({ + collMod: collection_projects, + validator: validationRules.validator, + validationLevel: validationRules.validationLevel, + validationAction: validationRules.validationAction, + }); + console.log(`Collection ${collection_projects} with validation rules created successfully.`); + yield client.close(); + }); +} +exports.createProjectCollectionWithValidation = createProjectCollectionWithValidation; diff --git a/build/projects/validationProjectsModel.d.ts b/build/projects/validationProjectsModel.d.ts new file mode 100644 index 0000000..e24a0ec --- /dev/null +++ b/build/projects/validationProjectsModel.d.ts @@ -0,0 +1,29 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IProjectDb } from '../interfaces'; +export declare const projectModel: import("mongoose").Model & IProjectDb & Required<{ + _id: string; +}>, any>; diff --git a/build/projects/validationProjectsModel.js b/build/projects/validationProjectsModel.js new file mode 100644 index 0000000..bbfe911 --- /dev/null +++ b/build/projects/validationProjectsModel.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.projectModel = void 0; +const mongoose_1 = require("mongoose"); +const projectSchema = new mongoose_1.Schema({ + _id: { type: String, required: true }, + user_id: { type: String, required: true, index: true }, + name: { type: String, required: true }, + clientName: { type: String, required: true }, + type: { type: String, required: true }, + snapshot: { type: String, required: false }, + favorite: { type: Boolean, required: true }, + clouds: { type: [String], default: [], ref: 'entity' }, + images: { type: [String], default: [], ref: 'entity' }, + bim: { type: [String], default: [], ref: 'entity' }, + projectQuota: { + pointCloudUsedMB: { type: Number, required: true }, + imageUsedMB: { type: Number, required: true }, + BIMUsedMB: { type: Number, required: true }, + }, + createdAt: { type: Number, required: true }, + modifiedAt: { type: Number, required: true }, + owner: { type: String, required: false }, + accessType: { type: String, required: false }, + publicAccessToken: { type: String, required: true }, + status: { type: String, required: true }, +}); +exports.projectModel = (0, mongoose_1.model)('project', projectSchema); diff --git a/build/users/services/createUserService.d.ts b/build/users/services/createUserService.d.ts new file mode 100644 index 0000000..717b62f --- /dev/null +++ b/build/users/services/createUserService.d.ts @@ -0,0 +1,2 @@ +import { IUsers } from '../../interfaces'; +export declare function createUserService(user: IUsers): Promise; diff --git a/build/users/services/createUserService.js b/build/users/services/createUserService.js new file mode 100644 index 0000000..50ba81b --- /dev/null +++ b/build/users/services/createUserService.js @@ -0,0 +1,60 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createUserService = void 0; +const validationUserModel_1 = require("../validationUserModel"); +const uuid_1 = require("uuid"); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function createUserService(user) { + return __awaiter(this, void 0, void 0, function* () { + try { + const existingUser = yield validationUserModel_1.UserModel.findOne({ email: user.email }); + if (existingUser) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ResourceExists; + throw err; + } + const newUser = new validationUserModel_1.UserModel({ + _id: (0, uuid_1.v4)(), + name: user.name, + lastName: user.lastName, + email: user.email, + password: user.password, + actingField: user.actingField, + phoneNumber: user.phoneNumber, + postalCode: user.postalCode, + useObjective: user.useObjective, + imagePath: user.imagePath, + street: user.street, + number: user.number, + complement: user.complement, + quota: { + BIMSizeQuotaMB: 5000, + pointCloudQuotaMB: 5000, + imageSizeQuotaMB: 5000, + BIMUsedMB: 0, + imageUsedMB: 0, + pointCloudUsedMB: 0, + }, + customerId: user.customerId, + }); + const savedUser = yield newUser.save(); + return savedUser; + } + catch (error) { + if (error !== duna_web_platform_error_defs_1.ErrorMessages.ResourceExists) { + error = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + error.Details = 'Possibly wrong data schema.'; + } + throw error; + } + }); +} +exports.createUserService = createUserService; diff --git a/build/users/services/deleteUserService.d.ts b/build/users/services/deleteUserService.d.ts new file mode 100644 index 0000000..83f05a5 --- /dev/null +++ b/build/users/services/deleteUserService.d.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +export declare function deleteUserService(userId: string): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ + _id: string; +}>) | null>; diff --git a/build/users/services/deleteUserService.js b/build/users/services/deleteUserService.js new file mode 100644 index 0000000..097dd49 --- /dev/null +++ b/build/users/services/deleteUserService.js @@ -0,0 +1,27 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteUserService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const validationUserModel_1 = require("../validationUserModel"); +function deleteUserService(userId) { + return __awaiter(this, void 0, void 0, function* () { + try { + return yield validationUserModel_1.UserModel.findOneAndDelete({ _id: userId }); + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Internal server Error '; + throw err; + } + }); +} +exports.deleteUserService = deleteUserService; diff --git a/build/users/services/getOneUserService.d.ts b/build/users/services/getOneUserService.d.ts new file mode 100644 index 0000000..8f7d2e7 --- /dev/null +++ b/build/users/services/getOneUserService.d.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +export declare function getOneUserService(_id: string): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ + _id: string; +}>) | null>; diff --git a/build/users/services/getOneUserService.js b/build/users/services/getOneUserService.js new file mode 100644 index 0000000..88556cc --- /dev/null +++ b/build/users/services/getOneUserService.js @@ -0,0 +1,28 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getOneUserService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const validationUserModel_1 = require("../validationUserModel"); +function getOneUserService(_id) { + return __awaiter(this, void 0, void 0, function* () { + try { + const user = yield validationUserModel_1.UserModel.findOne({ _id }); + return user; + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Internal server Error '; + throw err; + } + }); +} +exports.getOneUserService = getOneUserService; diff --git a/build/users/services/getUsersService.d.ts b/build/users/services/getUsersService.d.ts new file mode 100644 index 0000000..9602c32 --- /dev/null +++ b/build/users/services/getUsersService.d.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +export declare function getUsersService(): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ + _id: string; +}>)[]>; diff --git a/build/users/services/getUsersService.js b/build/users/services/getUsersService.js new file mode 100644 index 0000000..fada50f --- /dev/null +++ b/build/users/services/getUsersService.js @@ -0,0 +1,28 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getUsersService = void 0; +const validationUserModel_1 = require("../validationUserModel"); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function getUsersService() { + return __awaiter(this, void 0, void 0, function* () { + try { + const user = yield validationUserModel_1.UserModel.find(); + return user; + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Internal server Error '; + throw err; + } + }); +} +exports.getUsersService = getUsersService; diff --git a/build/users/services/loginService.d.ts b/build/users/services/loginService.d.ts new file mode 100644 index 0000000..f30fbd0 --- /dev/null +++ b/build/users/services/loginService.d.ts @@ -0,0 +1,2 @@ +import { IUsers } from '../../interfaces'; +export declare function getUserByEmail(email: string): Promise; diff --git a/build/users/services/loginService.js b/build/users/services/loginService.js new file mode 100644 index 0000000..b90a214 --- /dev/null +++ b/build/users/services/loginService.js @@ -0,0 +1,28 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getUserByEmail = void 0; +const validationUserModel_1 = require("../validationUserModel"); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function getUserByEmail(email) { + return __awaiter(this, void 0, void 0, function* () { + try { + const user = yield validationUserModel_1.UserModel.findOne({ email }).exec(); + return user; + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Internal server Error '; + throw err; + } + }); +} +exports.getUserByEmail = getUserByEmail; diff --git a/build/users/services/updateCustomerIdService.d.ts b/build/users/services/updateCustomerIdService.d.ts new file mode 100644 index 0000000..36f6882 --- /dev/null +++ b/build/users/services/updateCustomerIdService.d.ts @@ -0,0 +1,2 @@ +import { IUsers } from "../../interfaces"; +export declare function updateCustomerId(email: string, updates: Partial): Promise; diff --git a/build/users/services/updateCustomerIdService.js b/build/users/services/updateCustomerIdService.js new file mode 100644 index 0000000..4f74ad4 --- /dev/null +++ b/build/users/services/updateCustomerIdService.js @@ -0,0 +1,35 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateCustomerId = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const validationUserModel_1 = require("../validationUserModel"); +function updateCustomerId(email, updates) { + return __awaiter(this, void 0, void 0, function* () { + try { + const existingUser = yield validationUserModel_1.UserModel.findOne({ email: email }); + if (!existingUser) { + return null; + } + if (updates.customerId) + existingUser.customerId = updates.customerId; + yield existingUser.save(); + return existingUser; + } + catch (error) { + console.error('Error in updateUserService:', error); + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Error updating user data.'; + throw err; + } + }); +} +exports.updateCustomerId = updateCustomerId; diff --git a/build/users/services/updateUserService.d.ts b/build/users/services/updateUserService.d.ts new file mode 100644 index 0000000..cc3e1e3 --- /dev/null +++ b/build/users/services/updateUserService.d.ts @@ -0,0 +1,2 @@ +import { IUsers } from '../../interfaces'; +export declare function updateUserService(userId: string, updates: Partial): Promise; diff --git a/build/users/services/updateUserService.js b/build/users/services/updateUserService.js new file mode 100644 index 0000000..b284704 --- /dev/null +++ b/build/users/services/updateUserService.js @@ -0,0 +1,58 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateUserService = void 0; +const validationUserModel_1 = require("../validationUserModel"); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function updateUserService(userId, updates) { + return __awaiter(this, void 0, void 0, function* () { + try { + const existingUser = yield validationUserModel_1.UserModel.findById(userId); + if (!existingUser) { + return null; + } + if (updates.name) + existingUser.name = updates.name; + if (updates.lastName) + existingUser.lastName = updates.lastName; + if (updates.email) + existingUser.email = updates.email; + if (updates.password) + existingUser.password = updates.password; + if (updates.actingField) + existingUser.actingField = updates.actingField; + if (updates.phoneNumber) + existingUser.phoneNumber = updates.phoneNumber; + if (updates.postalCode) + existingUser.postalCode = updates.postalCode; + if (updates.useObjective) + existingUser.useObjective = updates.useObjective; + if (updates.imagePath) + existingUser.imagePath = updates.imagePath; + if (updates.street) + existingUser.street = updates.street; + if (updates.number) + existingUser.number = updates.number; + if (updates.complement) + existingUser.complement = updates.complement; + if (updates.quota) + existingUser.quota = updates.quota; + yield existingUser.save(); + return existingUser; + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Error updating user data.'; + throw err; + } + }); +} +exports.updateUserService = updateUserService; diff --git a/build/users/validationDbUsers.d.ts b/build/users/validationDbUsers.d.ts new file mode 100644 index 0000000..a5d5f32 --- /dev/null +++ b/build/users/validationDbUsers.d.ts @@ -0,0 +1 @@ +export declare function createUserCollectionWithValidation(uri: string, databaseName: string, collectionName: string): Promise; diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js new file mode 100644 index 0000000..fe39caf --- /dev/null +++ b/build/users/validationDbUsers.js @@ -0,0 +1,121 @@ +"use strict"; +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.createUserCollectionWithValidation = void 0; +const dotenv_1 = __importDefault(require("dotenv")); +const mongodb_1 = require("mongodb"); +dotenv_1.default.config(); +function createUserCollectionWithValidation(uri, databaseName, collectionName) { + return __awaiter(this, void 0, void 0, function* () { + const client = new mongodb_1.MongoClient(uri); + yield client.connect(); + const db = client.db(databaseName); + const colecao = db.collection(collectionName); + const validationRules = { + validator: { + $jsonSchema: { + bsonType: 'object', + required: [ + 'name', + 'lastName', + 'password', + 'postalCode', + 'street', + 'number', + 'quota', + ], + properties: { + name: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + lastName: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + password: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + postalCode: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + street: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + number: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + complement: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + quota: { + bsonType: 'object', + required: [ + 'pointCloudQuotaMB', + 'imageSizeQuotaMB', + 'BIMSizeQuotaMB', + 'pointCloudUsedMB', + 'imageUsedMB', + 'BIMUsedMB', + ], + properties: { + pointCloudQuotaMB: { + bsonType: 'number', + description: 'Quota para nuvem de pontos (number)', + }, + imageSizeQuotaMB: { + bsonType: 'number', + description: 'Quota para tamanho da imagem (number)', + }, + BIMSizeQuotaMB: { + bsonType: 'number', + description: 'Quota para tamanho do BIM (number)', + }, + pointCloudUsedMB: { + bsonType: 'number', + description: 'Uso de nuvem de pontos (number)', + }, + imageUsedMB: { + bsonType: 'number', + description: 'Uso de tamanho da imagem (number)', + }, + BIMUsedMB: { + bsonType: 'number', + description: 'Uso de tamanho do BIM (number)', + }, + }, + }, + }, + }, + }, + validationLevel: 'strict', + validationAction: 'error', + }; + yield colecao.createIndex({ _id: 1 }); + yield db.command({ + collMod: colecao.collectionName, + validator: validationRules.validator, + validationLevel: validationRules.validationLevel, + validationAction: validationRules.validationAction, + }); + console.log(`Coleção ${collectionName} com regras de validação criada com sucesso.`); + yield client.close(); + }); +} +exports.createUserCollectionWithValidation = createUserCollectionWithValidation; diff --git a/build/users/validationUserModel.d.ts b/build/users/validationUserModel.d.ts new file mode 100644 index 0000000..86c6c19 --- /dev/null +++ b/build/users/validationUserModel.d.ts @@ -0,0 +1,4 @@ +import { Model } from 'mongoose'; +import { IUsers } from '../interfaces'; +declare const UserModel: Model; +export { UserModel }; diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js new file mode 100644 index 0000000..2bbca45 --- /dev/null +++ b/build/users/validationUserModel.js @@ -0,0 +1,34 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UserModel = void 0; +const mongoose_1 = __importDefault(require("mongoose")); +const UserSchema = new mongoose_1.default.Schema({ + _id: { type: String, required: true }, + name: { type: String, required: true }, + lastName: { type: String, required: true }, + email: { type: String, unique: true }, + password: { type: String, required: true }, + actingField: { type: String, default: '' }, + phoneNumber: { type: String, default: '' }, + postalCode: { type: String, required: true, default: '' }, + useObjective: { type: String, default: '' }, + imagePath: { type: String, default: '' }, + street: { type: String, required: true, default: '' }, + number: { type: String, required: true, default: '' }, + complement: { type: String, default: '' }, + quota: { + pointCloudQuotaMB: { type: Number, required: true }, + imageSizeQuotaMB: { type: Number, required: true }, + BIMSizeQuotaMB: { type: Number, required: true }, + pointCloudUsedMB: { type: Number, required: true }, + imageUsedMB: { type: Number, required: true }, + BIMUsedMB: { type: Number, required: true }, + }, + customerId: { type: String, required: false }, + validatedMail: { type: Boolean, required: true, default: false }, +}); +const UserModel = mongoose_1.default.model('user', UserSchema); +exports.UserModel = UserModel; diff --git a/build/usersProject/UserService.d.ts b/build/usersProject/UserService.d.ts new file mode 100644 index 0000000..3774e0f --- /dev/null +++ b/build/usersProject/UserService.d.ts @@ -0,0 +1,34 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IUsers } from '../interfaces'; +export declare class UserService { + protected model: import("mongoose").Model & IUsers & Required<{ + _id: string; + }>, any>; + protected configure(): void; + get(user_id?: string, email?: string): Promise; + update(user: IUsers): Promise; +} diff --git a/build/usersProject/UserService.js b/build/usersProject/UserService.js new file mode 100644 index 0000000..ec1a453 --- /dev/null +++ b/build/usersProject/UserService.js @@ -0,0 +1,57 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UserService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const connection_1 = require("../connection"); +const validationUserModel_1 = require("../users/validationUserModel"); +class UserService { + constructor() { + this.model = validationUserModel_1.UserModel; + } + configure() { } + get(user_id, email) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + let user; + if (user_id) { + user = yield this.model.findById(user_id).lean().exec(); + } + else { + user = yield this.model.findOne({ email: email }).lean().exec(); + } + if (!user) { + const id = user_id ? user_id : email; + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = `User ${id} not found`; + throw err; + } + return user; + }); + } + update(user) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const user_record = yield this.model.findByIdAndUpdate(user._id, user, { + new: true, + }); + if (!user_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.UserNotFound; + err.Details = `User '${user._id}' not found'`; + throw err; + } + return user_record.toJSON(); + }); + } +} +exports.UserService = UserService; From 2379c20fa0c291d66344c1c01b12faffd9dc724b Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Sat, 13 Jan 2024 12:55:35 -0300 Subject: [PATCH 05/20] format --- src/users/services/updateCustomerIdService.ts | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/users/services/updateCustomerIdService.ts b/src/users/services/updateCustomerIdService.ts index 18a0460..fd54fe7 100644 --- a/src/users/services/updateCustomerIdService.ts +++ b/src/users/services/updateCustomerIdService.ts @@ -1,27 +1,26 @@ -import { ErrorMessages } from "duna-web-platform-error-defs"; -import { IUsers } from "../../interfaces"; -import { UserModel } from "../validationUserModel"; - - -export async function updateCustomerId( - email: string, - updates: Partial - ): Promise { - try { - const existingUser = await UserModel.findOne({ email: email }); - - if (!existingUser) { - return null; - } - if(updates.customerId) existingUser.customerId = updates.customerId - - await existingUser.save(); - - return existingUser; - } catch (error) { - console.error('Error in updateUserService:', error); - const err = ErrorMessages.InternalServerError; - err.Details = 'Error updating user data.'; - throw err; - } - } \ No newline at end of file +import { ErrorMessages } from 'duna-web-platform-error-defs' +import { IUsers } from '../../interfaces' +import { UserModel } from '../validationUserModel' + +export async function updateCustomerId( + email: string, + updates: Partial +): Promise { + try { + const existingUser = await UserModel.findOne({ email: email }) + + if (!existingUser) { + return null + } + if (updates.customerId) existingUser.customerId = updates.customerId + + await existingUser.save() + + return existingUser + } catch (error) { + console.error('Error in updateUserService:', error) + const err = ErrorMessages.InternalServerError + err.Details = 'Error updating user data.' + throw err + } +} From ffc0ae72a1f27fcb56553b6d22b02ddb13e8ae1f Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 14:50:17 -0300 Subject: [PATCH 06/20] change model and interface --- src/interfaces.ts | 6 +++++- src/users/validationUserModel.ts | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index 91176fc..dd556e7 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -15,7 +15,11 @@ export interface IUsers { complement: string quota: UserQuota validatedMail: boolean - customerId: string + paymentInfo: { + customerId?: string; + plan?: string; + expirationDate?: Date; + } [key: string]: any } diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index 9d56fc0..26b88e3 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -23,6 +23,11 @@ const UserSchema = new mongoose.Schema({ imageUsedMB: { type: Number, required: true }, BIMUsedMB: { type: Number, required: true }, }, + paymentInfo: { + customerId: { type: String, required: true, default:'' }, + plan: { type: String, required: true, default:'' }, + expirationDate: { type: Date, required: true, default:'' }, + }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, }) From 7a6848e5a10d56d86c4b6e802c0146862860de9f Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 18:43:03 -0300 Subject: [PATCH 07/20] fix:changes in user table and service --- src/interfaces.ts | 8 +++---- src/users/services/updateCustomerIdService.ts | 1 + src/users/validationDbUsers.ts | 22 +++++++++++++++++++ src/users/validationUserModel.ts | 8 +++---- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index dd556e7..7db8285 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -16,10 +16,10 @@ export interface IUsers { quota: UserQuota validatedMail: boolean paymentInfo: { - customerId?: string; - plan?: string; - expirationDate?: Date; - } + customerId: string + plan: string + expirationDate: Date + } [key: string]: any } diff --git a/src/users/services/updateCustomerIdService.ts b/src/users/services/updateCustomerIdService.ts index fd54fe7..a64bdef 100644 --- a/src/users/services/updateCustomerIdService.ts +++ b/src/users/services/updateCustomerIdService.ts @@ -2,6 +2,7 @@ import { ErrorMessages } from 'duna-web-platform-error-defs' import { IUsers } from '../../interfaces' import { UserModel } from '../validationUserModel' +//atualizar novos campos do paymentInfo export async function updateCustomerId( email: string, updates: Partial diff --git a/src/users/validationDbUsers.ts b/src/users/validationDbUsers.ts index bde3198..5c7c000 100644 --- a/src/users/validationDbUsers.ts +++ b/src/users/validationDbUsers.ts @@ -26,6 +26,7 @@ export async function createUserCollectionWithValidation( 'street', 'number', 'quota', + 'paymentInfo', ], properties: { name: { @@ -97,6 +98,27 @@ export async function createUserCollectionWithValidation( }, }, }, + paymentInfo: { + bsonType: 'object', + required: ['customerId', 'plan', 'expirationDate'], + properties: { + customerId: { + bsonType: 'string', + description: + 'Deve ser uma string e é obrigatório.', + }, + plan: { + bsonType: 'string', + description: + 'Deve ser uma string e é obrigatório.', + }, + expirationDate: { + bsonType: 'date', + description: + 'Deve ser uma data e é obrigatório.', + }, + }, + }, }, }, }, diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index 26b88e3..0cfb0b8 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -24,10 +24,10 @@ const UserSchema = new mongoose.Schema({ BIMUsedMB: { type: Number, required: true }, }, paymentInfo: { - customerId: { type: String, required: true, default:'' }, - plan: { type: String, required: true, default:'' }, - expirationDate: { type: Date, required: true, default:'' }, - }, + customerId: { type: String, required: true, default: '' }, + plan: { type: String, required: true, default: '' }, + expirationDate: { type: Date, required: true, default: '' }, + }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, }) From 99ac17fe974f29cde64c2a1759ca0fe39b681871 Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 18:43:46 -0300 Subject: [PATCH 08/20] fix:build --- build/interfaces.d.ts | 6 ++- .../services/updateCustomerIdService.d.ts | 2 +- .../users/services/updateCustomerIdService.js | 15 +++++++- build/users/validationDbUsers.js | 19 ++++++++++ build/users/validationUserModel.js | 5 +++ src/users/services/updateCustomerIdService.ts | 38 +++++++++++++------ 6 files changed, 71 insertions(+), 14 deletions(-) diff --git a/build/interfaces.d.ts b/build/interfaces.d.ts index 8dc7412..f6e77be 100644 --- a/build/interfaces.d.ts +++ b/build/interfaces.d.ts @@ -15,7 +15,11 @@ export interface IUsers { complement: string; quota: UserQuota; validatedMail: boolean; - customerId: string; + paymentInfo: { + customerId: string; + plan: string; + expirationDate: Date; + }; [key: string]: any; } export interface IEntityDb { diff --git a/build/users/services/updateCustomerIdService.d.ts b/build/users/services/updateCustomerIdService.d.ts index 36f6882..396e353 100644 --- a/build/users/services/updateCustomerIdService.d.ts +++ b/build/users/services/updateCustomerIdService.d.ts @@ -1,2 +1,2 @@ -import { IUsers } from "../../interfaces"; +import { IUsers } from '../../interfaces'; export declare function updateCustomerId(email: string, updates: Partial): Promise; diff --git a/build/users/services/updateCustomerIdService.js b/build/users/services/updateCustomerIdService.js index 4f74ad4..5bc21f0 100644 --- a/build/users/services/updateCustomerIdService.js +++ b/build/users/services/updateCustomerIdService.js @@ -19,8 +19,21 @@ function updateCustomerId(email, updates) { if (!existingUser) { return null; } - if (updates.customerId) + if (updates.customerId) { existingUser.customerId = updates.customerId; + } + if (updates.paymentInfo) { + const paymentInfoUpdates = updates.paymentInfo; + if (paymentInfoUpdates.customerId) { + existingUser.paymentInfo.customerId = paymentInfoUpdates.customerId; + } + if (paymentInfoUpdates.plan) { + existingUser.paymentInfo.plan = paymentInfoUpdates.plan; + } + if (paymentInfoUpdates.expirationDate) { + existingUser.paymentInfo.expirationDate = paymentInfoUpdates.expirationDate; + } + } yield existingUser.save(); return existingUser; } diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js index fe39caf..4f44ec9 100644 --- a/build/users/validationDbUsers.js +++ b/build/users/validationDbUsers.js @@ -34,6 +34,7 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { 'street', 'number', 'quota', + 'paymentInfo', ], properties: { name: { @@ -101,6 +102,24 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { }, }, }, + paymentInfo: { + bsonType: 'object', + required: ['customerId', 'plan', 'expirationDate'], + properties: { + customerId: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + plan: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + expirationDate: { + bsonType: 'date', + description: 'Deve ser uma data e é obrigatório.', + }, + }, + }, }, }, }, diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js index 2bbca45..6605eaa 100644 --- a/build/users/validationUserModel.js +++ b/build/users/validationUserModel.js @@ -27,6 +27,11 @@ const UserSchema = new mongoose_1.default.Schema({ imageUsedMB: { type: Number, required: true }, BIMUsedMB: { type: Number, required: true }, }, + paymentInfo: { + customerId: { type: String, required: true, default: '' }, + plan: { type: String, required: true, default: '' }, + expirationDate: { type: Date, required: true, default: '' }, + }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, }); diff --git a/src/users/services/updateCustomerIdService.ts b/src/users/services/updateCustomerIdService.ts index a64bdef..80662a3 100644 --- a/src/users/services/updateCustomerIdService.ts +++ b/src/users/services/updateCustomerIdService.ts @@ -2,26 +2,42 @@ import { ErrorMessages } from 'duna-web-platform-error-defs' import { IUsers } from '../../interfaces' import { UserModel } from '../validationUserModel' -//atualizar novos campos do paymentInfo + export async function updateCustomerId( email: string, updates: Partial ): Promise { try { - const existingUser = await UserModel.findOne({ email: email }) + const existingUser = await UserModel.findOne({ email: email }); if (!existingUser) { - return null + return null; + } + + if (updates.customerId) { + existingUser.customerId = updates.customerId; + } + + if (updates.paymentInfo) { + const paymentInfoUpdates = updates.paymentInfo; + if (paymentInfoUpdates.customerId) { + existingUser.paymentInfo.customerId = paymentInfoUpdates.customerId; + } + if (paymentInfoUpdates.plan) { + existingUser.paymentInfo.plan = paymentInfoUpdates.plan; + } + if (paymentInfoUpdates.expirationDate) { + existingUser.paymentInfo.expirationDate = paymentInfoUpdates.expirationDate; + } } - if (updates.customerId) existingUser.customerId = updates.customerId - await existingUser.save() + await existingUser.save(); - return existingUser + return existingUser; } catch (error) { - console.error('Error in updateUserService:', error) - const err = ErrorMessages.InternalServerError - err.Details = 'Error updating user data.' - throw err + console.error('Error in updateUserService:', error); + const err = ErrorMessages.InternalServerError; + err.Details = 'Error updating user data.'; + throw err; } -} +} \ No newline at end of file From e2035ff45e05a8f59dca8471ccb36737d2d0ddfe Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 18:54:28 -0300 Subject: [PATCH 09/20] fix:small adjust --- build/users/services/createUserService.js | 6 +++++- build/users/validationDbUsers.js | 6 +++--- build/users/validationUserModel.js | 6 +++--- src/users/services/createUserService.ts | 6 +++++- src/users/validationDbUsers.ts | 6 +++--- src/users/validationUserModel.ts | 6 +++--- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/build/users/services/createUserService.js b/build/users/services/createUserService.js index 50ba81b..14ab974 100644 --- a/build/users/services/createUserService.js +++ b/build/users/services/createUserService.js @@ -43,7 +43,11 @@ function createUserService(user) { imageUsedMB: 0, pointCloudUsedMB: 0, }, - customerId: user.customerId, + paymentInfo: { + customerId: user.paymentInfo.customerId || '', + plan: user.paymentInfo.plan || '', + expirationDate: user.paymentInfo.expirationDate || '', + }, }); const savedUser = yield newUser.save(); return savedUser; diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js index 4f44ec9..70025b7 100644 --- a/build/users/validationDbUsers.js +++ b/build/users/validationDbUsers.js @@ -108,15 +108,15 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { properties: { customerId: { bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', + description: 'Deve ser uma string .', }, plan: { bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', + description: 'Deve ser uma string .', }, expirationDate: { bsonType: 'date', - description: 'Deve ser uma data e é obrigatório.', + description: 'Deve ser uma data .', }, }, }, diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js index 6605eaa..eba6e1f 100644 --- a/build/users/validationUserModel.js +++ b/build/users/validationUserModel.js @@ -28,9 +28,9 @@ const UserSchema = new mongoose_1.default.Schema({ BIMUsedMB: { type: Number, required: true }, }, paymentInfo: { - customerId: { type: String, required: true, default: '' }, - plan: { type: String, required: true, default: '' }, - expirationDate: { type: Date, required: true, default: '' }, + customerId: { type: String, required: false, default: '' }, + plan: { type: String, required: false, default: '' }, + expirationDate: { type: Date, required: false, default: '' }, }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, diff --git a/src/users/services/createUserService.ts b/src/users/services/createUserService.ts index 026e283..2758b77 100644 --- a/src/users/services/createUserService.ts +++ b/src/users/services/createUserService.ts @@ -34,7 +34,11 @@ export async function createUserService(user: IUsers): Promise { imageUsedMB: 0, pointCloudUsedMB: 0, }, - customerId: user.customerId, + paymentInfo: { + customerId: user.paymentInfo.customerId || '', + plan: user.paymentInfo.plan || '', + expirationDate: user.paymentInfo.expirationDate || '', + }, }) const savedUser = await newUser.save() diff --git a/src/users/validationDbUsers.ts b/src/users/validationDbUsers.ts index 5c7c000..dc02f6d 100644 --- a/src/users/validationDbUsers.ts +++ b/src/users/validationDbUsers.ts @@ -105,17 +105,17 @@ export async function createUserCollectionWithValidation( customerId: { bsonType: 'string', description: - 'Deve ser uma string e é obrigatório.', + 'Deve ser uma string .', }, plan: { bsonType: 'string', description: - 'Deve ser uma string e é obrigatório.', + 'Deve ser uma string .', }, expirationDate: { bsonType: 'date', description: - 'Deve ser uma data e é obrigatório.', + 'Deve ser uma data .', }, }, }, diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index 0cfb0b8..cb3b25b 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -24,9 +24,9 @@ const UserSchema = new mongoose.Schema({ BIMUsedMB: { type: Number, required: true }, }, paymentInfo: { - customerId: { type: String, required: true, default: '' }, - plan: { type: String, required: true, default: '' }, - expirationDate: { type: Date, required: true, default: '' }, + customerId: { type: String, required: false, default: '' }, + plan: { type: String, required: false, default: '' }, + expirationDate: { type: Date, required: false, default: '' }, }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, From 86883cdafc34bf0cfb72a6c2ef7a89adac34cbeb Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 19:03:00 -0300 Subject: [PATCH 10/20] fix:table --- build/users/services/createUserService.js | 6 +++--- build/users/validationDbUsers.js | 19 ------------------- build/users/validationUserModel.js | 2 +- src/users/services/createUserService.ts | 6 +++--- src/users/validationDbUsers.ts | 22 ---------------------- src/users/validationUserModel.ts | 2 +- 6 files changed, 8 insertions(+), 49 deletions(-) diff --git a/build/users/services/createUserService.js b/build/users/services/createUserService.js index 14ab974..90d9545 100644 --- a/build/users/services/createUserService.js +++ b/build/users/services/createUserService.js @@ -44,9 +44,9 @@ function createUserService(user) { pointCloudUsedMB: 0, }, paymentInfo: { - customerId: user.paymentInfo.customerId || '', - plan: user.paymentInfo.plan || '', - expirationDate: user.paymentInfo.expirationDate || '', + customerId: user.paymentInfo.customerId, + plan: user.paymentInfo.plan, + expirationDate: user.paymentInfo.expirationDate, }, }); const savedUser = yield newUser.save(); diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js index 70025b7..fe39caf 100644 --- a/build/users/validationDbUsers.js +++ b/build/users/validationDbUsers.js @@ -34,7 +34,6 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { 'street', 'number', 'quota', - 'paymentInfo', ], properties: { name: { @@ -102,24 +101,6 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { }, }, }, - paymentInfo: { - bsonType: 'object', - required: ['customerId', 'plan', 'expirationDate'], - properties: { - customerId: { - bsonType: 'string', - description: 'Deve ser uma string .', - }, - plan: { - bsonType: 'string', - description: 'Deve ser uma string .', - }, - expirationDate: { - bsonType: 'date', - description: 'Deve ser uma data .', - }, - }, - }, }, }, }, diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js index eba6e1f..76ac5dd 100644 --- a/build/users/validationUserModel.js +++ b/build/users/validationUserModel.js @@ -30,7 +30,7 @@ const UserSchema = new mongoose_1.default.Schema({ paymentInfo: { customerId: { type: String, required: false, default: '' }, plan: { type: String, required: false, default: '' }, - expirationDate: { type: Date, required: false, default: '' }, + expirationDate: { type: String, required: false, default: '' }, }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, diff --git a/src/users/services/createUserService.ts b/src/users/services/createUserService.ts index 2758b77..bd0148c 100644 --- a/src/users/services/createUserService.ts +++ b/src/users/services/createUserService.ts @@ -35,9 +35,9 @@ export async function createUserService(user: IUsers): Promise { pointCloudUsedMB: 0, }, paymentInfo: { - customerId: user.paymentInfo.customerId || '', - plan: user.paymentInfo.plan || '', - expirationDate: user.paymentInfo.expirationDate || '', + customerId: user.paymentInfo.customerId , + plan: user.paymentInfo.plan , + expirationDate: user.paymentInfo.expirationDate , }, }) diff --git a/src/users/validationDbUsers.ts b/src/users/validationDbUsers.ts index dc02f6d..bde3198 100644 --- a/src/users/validationDbUsers.ts +++ b/src/users/validationDbUsers.ts @@ -26,7 +26,6 @@ export async function createUserCollectionWithValidation( 'street', 'number', 'quota', - 'paymentInfo', ], properties: { name: { @@ -98,27 +97,6 @@ export async function createUserCollectionWithValidation( }, }, }, - paymentInfo: { - bsonType: 'object', - required: ['customerId', 'plan', 'expirationDate'], - properties: { - customerId: { - bsonType: 'string', - description: - 'Deve ser uma string .', - }, - plan: { - bsonType: 'string', - description: - 'Deve ser uma string .', - }, - expirationDate: { - bsonType: 'date', - description: - 'Deve ser uma data .', - }, - }, - }, }, }, }, diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index cb3b25b..9a6f753 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -26,7 +26,7 @@ const UserSchema = new mongoose.Schema({ paymentInfo: { customerId: { type: String, required: false, default: '' }, plan: { type: String, required: false, default: '' }, - expirationDate: { type: Date, required: false, default: '' }, + expirationDate: { type: String, required: false, default: '' }, }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, From 40d469f7ab37ecd0dd333020ee6cbf25e44db038 Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 20:28:16 -0300 Subject: [PATCH 11/20] fix:refactor updateCustomerId --- build/connection.d.ts | 3 - build/connection.js | 50 ----- build/entity/services/EntityService.d.ts | 58 ------ build/entity/services/EntityService.js | 173 ------------------ build/entity/validationEntityDb.d.ts | 1 - build/entity/validationEntityDb.js | 83 --------- build/entity/validationEntityModel.d.ts | 29 --- build/entity/validationEntityModel.js | 15 -- build/index.d.ts | 25 --- build/index.js | 45 ----- build/interfaces.d.ts | 113 ------------ build/interfaces.js | 32 ---- .../services/OrganizationService.d.ts | 39 ---- .../services/OrganizationService.js | 118 ------------ build/organizations/validationOrgDb.d.ts | 1 - build/organizations/validationOrgDb.js | 82 --------- build/organizations/validationOrgModel.d.ts | 29 --- build/organizations/validationOrgModel.js | 18 -- build/projects/services/ProjectService.d.ts | 43 ----- build/projects/services/ProjectService.js | 156 ---------------- build/projects/validationProjectsDb.d.ts | 1 - build/projects/validationProjectsDb.js | 140 -------------- build/projects/validationProjectsModel.d.ts | 29 --- build/projects/validationProjectsModel.js | 28 --- build/users/services/createUserService.d.ts | 2 - build/users/services/createUserService.js | 64 ------- build/users/services/deleteUserService.d.ts | 28 --- build/users/services/deleteUserService.js | 27 --- build/users/services/getOneUserService.d.ts | 28 --- build/users/services/getOneUserService.js | 28 --- build/users/services/getUsersService.d.ts | 28 --- build/users/services/getUsersService.js | 28 --- build/users/services/loginService.d.ts | 2 - build/users/services/loginService.js | 28 --- .../services/updateCustomerIdService.d.ts | 2 - .../users/services/updateCustomerIdService.js | 48 ----- build/users/services/updateUserService.d.ts | 2 - build/users/services/updateUserService.js | 58 ------ build/users/validationDbUsers.d.ts | 1 - build/users/validationDbUsers.js | 121 ------------ build/users/validationUserModel.d.ts | 4 - build/users/validationUserModel.js | 39 ---- build/usersProject/UserService.d.ts | 34 ---- build/usersProject/UserService.js | 57 ------ src/users/services/updateCustomerIdService.ts | 60 +++--- 45 files changed, 27 insertions(+), 1973 deletions(-) delete mode 100644 build/connection.d.ts delete mode 100644 build/connection.js delete mode 100644 build/entity/services/EntityService.d.ts delete mode 100644 build/entity/services/EntityService.js delete mode 100644 build/entity/validationEntityDb.d.ts delete mode 100644 build/entity/validationEntityDb.js delete mode 100644 build/entity/validationEntityModel.d.ts delete mode 100644 build/entity/validationEntityModel.js delete mode 100644 build/index.d.ts delete mode 100644 build/index.js delete mode 100644 build/interfaces.d.ts delete mode 100644 build/interfaces.js delete mode 100644 build/organizations/services/OrganizationService.d.ts delete mode 100644 build/organizations/services/OrganizationService.js delete mode 100644 build/organizations/validationOrgDb.d.ts delete mode 100644 build/organizations/validationOrgDb.js delete mode 100644 build/organizations/validationOrgModel.d.ts delete mode 100644 build/organizations/validationOrgModel.js delete mode 100644 build/projects/services/ProjectService.d.ts delete mode 100644 build/projects/services/ProjectService.js delete mode 100644 build/projects/validationProjectsDb.d.ts delete mode 100644 build/projects/validationProjectsDb.js delete mode 100644 build/projects/validationProjectsModel.d.ts delete mode 100644 build/projects/validationProjectsModel.js delete mode 100644 build/users/services/createUserService.d.ts delete mode 100644 build/users/services/createUserService.js delete mode 100644 build/users/services/deleteUserService.d.ts delete mode 100644 build/users/services/deleteUserService.js delete mode 100644 build/users/services/getOneUserService.d.ts delete mode 100644 build/users/services/getOneUserService.js delete mode 100644 build/users/services/getUsersService.d.ts delete mode 100644 build/users/services/getUsersService.js delete mode 100644 build/users/services/loginService.d.ts delete mode 100644 build/users/services/loginService.js delete mode 100644 build/users/services/updateCustomerIdService.d.ts delete mode 100644 build/users/services/updateCustomerIdService.js delete mode 100644 build/users/services/updateUserService.d.ts delete mode 100644 build/users/services/updateUserService.js delete mode 100644 build/users/validationDbUsers.d.ts delete mode 100644 build/users/validationDbUsers.js delete mode 100644 build/users/validationUserModel.d.ts delete mode 100644 build/users/validationUserModel.js delete mode 100644 build/usersProject/UserService.d.ts delete mode 100644 build/usersProject/UserService.js diff --git a/build/connection.d.ts b/build/connection.d.ts deleted file mode 100644 index 5edda3e..0000000 --- a/build/connection.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare function connectToDatabase(url: string, databaseName: string): Promise; -export declare function checkConnectionStatus(): void; -export declare function subscribeToDatabaseEvents(): void; diff --git a/build/connection.js b/build/connection.js deleted file mode 100644 index 560ad28..0000000 --- a/build/connection.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; -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.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = void 0; -const mongoose_1 = __importDefault(require("mongoose")); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function connectToDatabase(url, databaseName) { - return __awaiter(this, void 0, void 0, function* () { - try { - yield mongoose_1.default.connect(`${url}/${databaseName}`, {}); - console.log(`Conectado ao banco de dados: ${databaseName}`); - } - catch (error) { - throw error; - } - }); -} -exports.connectToDatabase = connectToDatabase; -function checkConnectionStatus() { - // 1 -> Connected - if (mongoose_1.default.connection.readyState != 1) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = `MongoDB disconnected`; - throw err; - } -} -exports.checkConnectionStatus = checkConnectionStatus; -function subscribeToDatabaseEvents() { - mongoose_1.default.connection.on('connected', () => { - console.log(`⚡️[database]: MongoDB connected`); - }); - mongoose_1.default.connection.on('error', (error) => { - console.log(`⚡️[database]: MongoDB Error - ${error}`); - }); - mongoose_1.default.connection.on('disconnected', () => { - console.log(`⚡️[database]: MongoDB Disconnected`); - }); -} -exports.subscribeToDatabaseEvents = subscribeToDatabaseEvents; diff --git a/build/entity/services/EntityService.d.ts b/build/entity/services/EntityService.d.ts deleted file mode 100644 index 1cfec63..0000000 --- a/build/entity/services/EntityService.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IEntityDb } from '../../interfaces'; -export declare class EntityService { - protected model: import("mongoose").Model & IEntityDb & Required<{ - _id: string; - }>, any>; - protected configure(): void; - insert(entity: IEntityDb): Promise; - get(entity_id: string): Promise; - getByName(project_id: string, entity_name: string): Promise; - update(entity: IEntityDb): Promise; - remove(entity_id: string): Promise; - removeAllFromUser(user_id: string): Promise; - exists(entity_id: string): Promise; - existsWithName(project_id: string, entity_name: string): Promise; - listAllFromProject(project_id: string): Promise; - /** - * Assign a parent entity to another entity. This essentially - * makes them a `child` entity. Child entities are not allowed - * to be processed. (business logic) - * - * @param project_id - * @param entity_name - * @param parent_entity_name - */ - assignParentName(project_id: string, entity_name: string, parent_entity_name: string): Promise; - /** - * Promote entity. Removes the parent field and allows them to be processed - * (business logic) - * @param project_id - * @param entity_name - */ - promoteEntity(project_id: string, entity_name: string): Promise; -} diff --git a/build/entity/services/EntityService.js b/build/entity/services/EntityService.js deleted file mode 100644 index 1e4da80..0000000 --- a/build/entity/services/EntityService.js +++ /dev/null @@ -1,173 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.EntityService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const connection_1 = require("../../connection"); -const validationEntityModel_1 = require("../validationEntityModel"); -class EntityService { - constructor() { - this.model = validationEntityModel_1.entityModel; - } - configure() { } - insert(entity) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entity_record = new this.model(entity); - yield entity_record.save(); - return entity_record.toJSON(); - }); - } - get(entity_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entity_record = yield this.model.findById(entity_id).lean().exec(); - if (!entity_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - throw err; - } - return entity_record; - }); - } - getByName(project_id, entity_name) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entity_record = yield this.model - .findOne({ projectId: project_id, name: entity_name }) - .lean() - .exec(); - if (!entity_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - throw err; - } - return entity_record; - }); - } - update(entity) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entity_record = yield this.model - .findByIdAndUpdate(entity._id, entity, { - new: true, - }) - .lean() - .exec(); - if (!entity_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - throw err; - } - return entity_record; - }); - } - remove(entity_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = yield this.exists(entity_id); - if (!exists) { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - throw err; - } - yield this.model.findByIdAndRemove(entity_id); - }); - } - removeAllFromUser(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - yield this.model.deleteMany({ user_id: user_id }); - }); - } - exists(entity_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = (yield this.model.exists({ _id: entity_id }).lean().exec()) != null; - return exists; - }); - } - existsWithName(project_id, entity_name) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project = yield this.model - .findOne({ projectId: project_id, name: entity_name }) - .lean() - .exec(); - return project != null; - }); - } - listAllFromProject(project_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const entities = yield this.model - .find({ proje: project_id }) - .lean() - .exec(); - return entities; - }); - } - /** - * Assign a parent entity to another entity. This essentially - * makes them a `child` entity. Child entities are not allowed - * to be processed. (business logic) - * - * @param project_id - * @param entity_name - * @param parent_entity_name - */ - assignParentName(project_id, entity_name, parent_entity_name) { - return __awaiter(this, void 0, void 0, function* () { - // Check if entity exist. - const child_entity = yield this.getByName(project_id, entity_name); - if (!(yield this.existsWithName(project_id, parent_entity_name))) { - { - const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; - err.Details = `Parent Name: ${parent_entity_name}`; - throw err; - } - } - child_entity.parentName = parent_entity_name; - this.update(child_entity); - }); - } - /** - * Promote entity. Removes the parent field and allows them to be processed - * (business logic) - * @param project_id - * @param entity_name - */ - promoteEntity(project_id, entity_name) { - return __awaiter(this, void 0, void 0, function* () { - // Check if entity exist. - const child_entity = yield this.getByName(project_id, entity_name); - if (child_entity.parentName === undefined) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = - 'Entity is not a chilld, or does not have parent property.'; - throw err; - } - const entity = yield this.model.findOne({ - projectId: project_id, - name: entity_name, - }); - // Assigning document properties to undefined removes them. - entity.parentName = undefined; - yield entity.save(); - }); - } -} -exports.EntityService = EntityService; diff --git a/build/entity/validationEntityDb.d.ts b/build/entity/validationEntityDb.d.ts deleted file mode 100644 index 666cb38..0000000 --- a/build/entity/validationEntityDb.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function createEntityCollectionWithValidation(uri: string, databaseName: string, collectionName: string): Promise; diff --git a/build/entity/validationEntityDb.js b/build/entity/validationEntityDb.js deleted file mode 100644 index 04c8ee6..0000000 --- a/build/entity/validationEntityDb.js +++ /dev/null @@ -1,83 +0,0 @@ -"use strict"; -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.createEntityCollectionWithValidation = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -const mongodb_1 = require("mongodb"); -dotenv_1.default.config(); -function createEntityCollectionWithValidation(uri, databaseName, collectionName) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(uri); - yield client.connect(); - const db = client.db(databaseName); - const colecao = db.collection(collectionName); - const validationRules = { - validator: { - $jsonSchema: { - bsonType: 'object', - required: [ - 'projectId', - 'type', - 'name', - 'location', - 'sizeMB', - 'shareGroup', - ], - properties: { - projectId: { - bsonType: 'string', - description: 'Project ID must be a string and is required.', - }, - type: { - bsonType: 'string', - description: 'Type must be a string and is required.', - }, - name: { - bsonType: 'string', - description: 'Name must be a string and is required.', - }, - location: { - bsonType: 'string', - description: 'Location must be a string and is required.', - }, - sizeMB: { - bsonType: 'number', - description: 'SizeMB must be a number and is required.', - }, - shareGroup: { - bsonType: 'string', - description: 'Share group must be a string and is required.', - }, - parentName: { - bsonType: 'string', - description: 'Holds a name reference to a parent entity. Not required.', - }, - }, - }, - }, - validationLevel: 'strict', - validationAction: 'error', - }; - yield colecao.createIndex({ projectId: 1 }); - yield db.command({ - collMod: colecao.collectionName, - validator: validationRules.validator, - validationLevel: validationRules.validationLevel, - validationAction: validationRules.validationAction, - }); - console.log(`Collection ${collectionName} with validation rules created successfully.`); - yield client.close(); - }); -} -exports.createEntityCollectionWithValidation = createEntityCollectionWithValidation; diff --git a/build/entity/validationEntityModel.d.ts b/build/entity/validationEntityModel.d.ts deleted file mode 100644 index 1a56a9c..0000000 --- a/build/entity/validationEntityModel.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IEntityDb } from '../interfaces'; -export declare const entityModel: import("mongoose").Model & IEntityDb & Required<{ - _id: string; -}>, any>; diff --git a/build/entity/validationEntityModel.js b/build/entity/validationEntityModel.js deleted file mode 100644 index ee39e35..0000000 --- a/build/entity/validationEntityModel.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.entityModel = void 0; -const mongoose_1 = require("mongoose"); -const entitySchema = new mongoose_1.Schema({ - _id: { type: String, required: true }, - projectId: { type: String, required: true, index: true }, - type: { type: String, required: true }, - name: { type: String, required: true }, - location: { type: String, required: true }, - sizeMB: { type: Number, required: true }, - shareGroup: { type: String, required: true }, - parentName: { type: String, requred: false }, -}); -exports.entityModel = (0, mongoose_1.model)('entity', entitySchema); diff --git a/build/index.d.ts b/build/index.d.ts deleted file mode 100644 index c25ed8e..0000000 --- a/build/index.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { createUserCollectionWithValidation } from './users/validationDbUsers'; -import { UserModel } from './users/validationUserModel'; -import { IMemberDb, IUser, IUsers } from './interfaces'; -import { connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents } from './connection'; -import { IEntityDb } from './interfaces'; -import { IProjectDb } from './interfaces'; -import { IOrganizationDb } from './interfaces'; -import { entityModel } from './entity/validationEntityModel'; -import { projectModel } from './projects/validationProjectsModel'; -import { organizationModel } from './organizations/validationOrgModel'; -import { createEntityCollectionWithValidation } from './entity/validationEntityDb'; -import { createProjectCollectionWithValidation } from './projects/validationProjectsDb'; -import { createOrganizationCollectionWithValidation } from './organizations/validationOrgDb'; -import { createUserService } from './users/services/createUserService'; -import { getUserByEmail } from './users/services/loginService'; -import { deleteUserService } from './users/services/deleteUserService'; -import { getOneUserService } from './users/services/getOneUserService'; -import { getUsersService } from './users/services/getUsersService'; -import { EntityService } from './entity/services/EntityService'; -import { ProjectService } from './projects/services/ProjectService'; -import { OrganizationService } from './organizations/services/OrganizationService'; -import { updateUserService } from './users/services/updateUserService'; -import { UserService } from './usersProject/UserService'; -import { updateCustomerId } from './users/services/updateCustomerIdService'; -export { createUserCollectionWithValidation, connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents, createEntityCollectionWithValidation, createProjectCollectionWithValidation, createOrganizationCollectionWithValidation, deleteUserService, getOneUserService, getUsersService, createUserService, updateUserService, getUserByEmail, updateCustomerId, UserService, OrganizationService, EntityService, ProjectService, UserModel, entityModel, organizationModel, IUsers, IUser, IEntityDb, IProjectDb, projectModel, IOrganizationDb, IMemberDb, }; diff --git a/build/index.js b/build/index.js deleted file mode 100644 index ac81097..0000000 --- a/build/index.js +++ /dev/null @@ -1,45 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.projectModel = exports.organizationModel = exports.entityModel = exports.UserModel = exports.ProjectService = exports.EntityService = exports.OrganizationService = exports.UserService = exports.updateCustomerId = exports.getUserByEmail = exports.updateUserService = exports.createUserService = exports.getUsersService = exports.getOneUserService = exports.deleteUserService = exports.createOrganizationCollectionWithValidation = exports.createProjectCollectionWithValidation = exports.createEntityCollectionWithValidation = exports.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = exports.createUserCollectionWithValidation = void 0; -const validationDbUsers_1 = require("./users/validationDbUsers"); -Object.defineProperty(exports, "createUserCollectionWithValidation", { enumerable: true, get: function () { return validationDbUsers_1.createUserCollectionWithValidation; } }); -const validationUserModel_1 = require("./users/validationUserModel"); -Object.defineProperty(exports, "UserModel", { enumerable: true, get: function () { return validationUserModel_1.UserModel; } }); -const connection_1 = require("./connection"); -Object.defineProperty(exports, "connectToDatabase", { enumerable: true, get: function () { return connection_1.connectToDatabase; } }); -Object.defineProperty(exports, "checkConnectionStatus", { enumerable: true, get: function () { return connection_1.checkConnectionStatus; } }); -Object.defineProperty(exports, "subscribeToDatabaseEvents", { enumerable: true, get: function () { return connection_1.subscribeToDatabaseEvents; } }); -const validationEntityModel_1 = require("./entity/validationEntityModel"); -Object.defineProperty(exports, "entityModel", { enumerable: true, get: function () { return validationEntityModel_1.entityModel; } }); -const validationProjectsModel_1 = require("./projects/validationProjectsModel"); -Object.defineProperty(exports, "projectModel", { enumerable: true, get: function () { return validationProjectsModel_1.projectModel; } }); -const validationOrgModel_1 = require("./organizations/validationOrgModel"); -Object.defineProperty(exports, "organizationModel", { enumerable: true, get: function () { return validationOrgModel_1.organizationModel; } }); -const validationEntityDb_1 = require("./entity/validationEntityDb"); -Object.defineProperty(exports, "createEntityCollectionWithValidation", { enumerable: true, get: function () { return validationEntityDb_1.createEntityCollectionWithValidation; } }); -const validationProjectsDb_1 = require("./projects/validationProjectsDb"); -Object.defineProperty(exports, "createProjectCollectionWithValidation", { enumerable: true, get: function () { return validationProjectsDb_1.createProjectCollectionWithValidation; } }); -const validationOrgDb_1 = require("./organizations/validationOrgDb"); -Object.defineProperty(exports, "createOrganizationCollectionWithValidation", { enumerable: true, get: function () { return validationOrgDb_1.createOrganizationCollectionWithValidation; } }); -const createUserService_1 = require("./users/services/createUserService"); -Object.defineProperty(exports, "createUserService", { enumerable: true, get: function () { return createUserService_1.createUserService; } }); -const loginService_1 = require("./users/services/loginService"); -Object.defineProperty(exports, "getUserByEmail", { enumerable: true, get: function () { return loginService_1.getUserByEmail; } }); -const deleteUserService_1 = require("./users/services/deleteUserService"); -Object.defineProperty(exports, "deleteUserService", { enumerable: true, get: function () { return deleteUserService_1.deleteUserService; } }); -const getOneUserService_1 = require("./users/services/getOneUserService"); -Object.defineProperty(exports, "getOneUserService", { enumerable: true, get: function () { return getOneUserService_1.getOneUserService; } }); -const getUsersService_1 = require("./users/services/getUsersService"); -Object.defineProperty(exports, "getUsersService", { enumerable: true, get: function () { return getUsersService_1.getUsersService; } }); -const EntityService_1 = require("./entity/services/EntityService"); -Object.defineProperty(exports, "EntityService", { enumerable: true, get: function () { return EntityService_1.EntityService; } }); -const ProjectService_1 = require("./projects/services/ProjectService"); -Object.defineProperty(exports, "ProjectService", { enumerable: true, get: function () { return ProjectService_1.ProjectService; } }); -const OrganizationService_1 = require("./organizations/services/OrganizationService"); -Object.defineProperty(exports, "OrganizationService", { enumerable: true, get: function () { return OrganizationService_1.OrganizationService; } }); -const updateUserService_1 = require("./users/services/updateUserService"); -Object.defineProperty(exports, "updateUserService", { enumerable: true, get: function () { return updateUserService_1.updateUserService; } }); -const UserService_1 = require("./usersProject/UserService"); -Object.defineProperty(exports, "UserService", { enumerable: true, get: function () { return UserService_1.UserService; } }); -const updateCustomerIdService_1 = require("./users/services/updateCustomerIdService"); -Object.defineProperty(exports, "updateCustomerId", { enumerable: true, get: function () { return updateCustomerIdService_1.updateCustomerId; } }); diff --git a/build/interfaces.d.ts b/build/interfaces.d.ts deleted file mode 100644 index f6e77be..0000000 --- a/build/interfaces.d.ts +++ /dev/null @@ -1,113 +0,0 @@ -export interface IUsers { - _id: string; - name: string; - lastName: string; - email: string; - password: string; - actingField: string; - phoneNumber: string; - postalCode: string; - useObjective: string; - imagePath: string; - cep: string; - street: string; - number: string; - complement: string; - quota: UserQuota; - validatedMail: boolean; - paymentInfo: { - customerId: string; - plan: string; - expirationDate: Date; - }; - [key: string]: any; -} -export interface IEntityDb { - _id: string; - projectId: string; - type: EntityType; - name: string; - location: string; - sizeMB: number; - shareGroup: ShareGroupType; - parentName?: string; -} -/** - * Project level quota. Contains summed up entity sized. - */ -export interface ProjectQuota { - pointCloudUsedMB: number; - imageUsedMB: number; - BIMUsedMB: number; -} -/** - * User level quota. Contains quota and used space from all projects. - */ -export interface UserQuota { - pointCloudQuotaMB: number; - imageSizeQuotaMB: number; - BIMSizeQuotaMB: number; - pointCloudUsedMB: number; - imageUsedMB: number; - BIMUsedMB: number; -} -export interface IProjectDb { - _id: string; - user_id: string; - name: string; - clientName: string; - type: string; - snapshot?: string; - favorite: boolean; - clouds: Array; - images: Array; - bim: Array; - projectQuota: ProjectQuota; - createdAt: number; - modifiedAt: number; - publicAccessToken: string; - status: ProjectStatus; - owner?: string; - accessType?: ProjectAccessType; -} -export interface IOrganizationDb { - _id: string; - memberLimit: number; - members: Array; - name: string; - type: string; -} -export interface IMemberDb { - user: string; - role: OrganizationMemberRole; -} -export interface IUser { - _id: string; - name: string; - lastName: string; - email: string; -} -export declare enum OrganizationMemberRole { - VIEWER = "VIEWER", - EDITOR = "EDITOR", - ADMIN = "ADMIN", - OWNER = "OWNER" -} -export declare enum ProjectStatus { - IN_PROGRESS = "IN_PROGRESS", - FINISHED = "FINISHED" -} -export declare enum ProjectAccessType { - INTERNAL = "INTERNAL", - PRIVATE = "PRIVATE" -} -export declare enum ShareGroupType { - Public = "public", - Private = "private" -} -export declare enum EntityType { - PointCloud = "clouds", - Image = "images", - BIM = "bim", - Unknown = "unknown" -} diff --git a/build/interfaces.js b/build/interfaces.js deleted file mode 100644 index 21cd19e..0000000 --- a/build/interfaces.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.EntityType = exports.ShareGroupType = exports.ProjectAccessType = exports.ProjectStatus = exports.OrganizationMemberRole = void 0; -var OrganizationMemberRole; -(function (OrganizationMemberRole) { - OrganizationMemberRole["VIEWER"] = "VIEWER"; - OrganizationMemberRole["EDITOR"] = "EDITOR"; - OrganizationMemberRole["ADMIN"] = "ADMIN"; - OrganizationMemberRole["OWNER"] = "OWNER"; -})(OrganizationMemberRole || (exports.OrganizationMemberRole = OrganizationMemberRole = {})); -var ProjectStatus; -(function (ProjectStatus) { - ProjectStatus["IN_PROGRESS"] = "IN_PROGRESS"; - ProjectStatus["FINISHED"] = "FINISHED"; -})(ProjectStatus || (exports.ProjectStatus = ProjectStatus = {})); -var ProjectAccessType; -(function (ProjectAccessType) { - ProjectAccessType["INTERNAL"] = "INTERNAL"; - ProjectAccessType["PRIVATE"] = "PRIVATE"; -})(ProjectAccessType || (exports.ProjectAccessType = ProjectAccessType = {})); -var ShareGroupType; -(function (ShareGroupType) { - ShareGroupType["Public"] = "public"; - ShareGroupType["Private"] = "private"; -})(ShareGroupType || (exports.ShareGroupType = ShareGroupType = {})); -var EntityType; -(function (EntityType) { - EntityType["PointCloud"] = "clouds"; - EntityType["Image"] = "images"; - EntityType["BIM"] = "bim"; - EntityType["Unknown"] = "unknown"; -})(EntityType || (exports.EntityType = EntityType = {})); diff --git a/build/organizations/services/OrganizationService.d.ts b/build/organizations/services/OrganizationService.d.ts deleted file mode 100644 index afa244a..0000000 --- a/build/organizations/services/OrganizationService.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IOrganizationDb } from '../../interfaces'; -export declare class OrganizationService { - protected model: import("mongoose").Model & IOrganizationDb & Required<{ - _id: string; - }>, any>; - protected configure(): void; - insert(organization: IOrganizationDb): Promise; - get(organization_id: string): Promise; - getPopulated(organization_id: string): Promise; - update(organization: IOrganizationDb): Promise; - remove(organization_id: string): Promise; - exists(organization_id: string): Promise; - listAllFromUser(user_id: string): Promise>; -} diff --git a/build/organizations/services/OrganizationService.js b/build/organizations/services/OrganizationService.js deleted file mode 100644 index daa61a6..0000000 --- a/build/organizations/services/OrganizationService.js +++ /dev/null @@ -1,118 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.OrganizationService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const connection_1 = require("../../connection"); -const validationOrgModel_1 = require("../validationOrgModel"); -const validationUserModel_1 = require("../../users/validationUserModel"); -class OrganizationService { - constructor() { - this.model = validationOrgModel_1.organizationModel; - } - configure() { } - insert(organization) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organization_record = new this.model(organization); - yield organization_record.save(); - return organization_record.toJSON(); - }); - } - get(organization_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organization_record = yield this.model - .findById(organization_id) - .lean() - .exec(); - if (!organization_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; - err.Details = `Organization '${organization_id}' not found'`; - throw err; - } - return organization_record; - }); - } - getPopulated(organization_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organization_record = yield this.model - .findById(organization_id) - .populate({ - path: 'members.user', - model: validationUserModel_1.UserModel, - select: '_id name lastName email', - }) - .lean() - .exec(); - if (!organization_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; - err.Details = `Organization '${organization_id}' not found'`; - throw err; - } - return organization_record; - }); - } - update(organization) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organization_record = yield this.model.findByIdAndUpdate(organization._id, organization, { - new: true, - }); - if (!organization_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; - err.Details = `Organization '${organization._id}' not found'`; - throw err; - } - return organization_record.toJSON(); - }); - } - remove(organization_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = yield this.exists(organization_id); - if (!exists) { - const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; - err.Details = `Organization '${organization_id}' not found'`; - throw err; - } - yield this.model.findByIdAndRemove(organization_id); - }); - } - exists(organization_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = (yield this.model.exists({ _id: organization_id }).lean().exec()) != - null; - return exists; - }); - } - listAllFromUser(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const organizations = yield this.model - .find({ 'members.user': user_id }) - .select('_id name members') - .lean() - .exec(); - return organizations; - }); - } -} -exports.OrganizationService = OrganizationService; diff --git a/build/organizations/validationOrgDb.d.ts b/build/organizations/validationOrgDb.d.ts deleted file mode 100644 index 3904440..0000000 --- a/build/organizations/validationOrgDb.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function createOrganizationCollectionWithValidation(uri: string, databaseName: string, collection_organizations: string): Promise; diff --git a/build/organizations/validationOrgDb.js b/build/organizations/validationOrgDb.js deleted file mode 100644 index 09b565b..0000000 --- a/build/organizations/validationOrgDb.js +++ /dev/null @@ -1,82 +0,0 @@ -"use strict"; -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.createOrganizationCollectionWithValidation = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -const mongodb_1 = require("mongodb"); -dotenv_1.default.config(); -function createOrganizationCollectionWithValidation(uri, databaseName, collection_organizations) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(uri); - yield client.connect(); - const db = client.db(databaseName); - const colecao = db.collection(collection_organizations); - const validationRules = { - validator: { - $jsonSchema: { - bsonType: 'object', - required: ['_id', 'memberLimit', 'name', 'type', 'members'], - properties: { - _id: { - bsonType: 'string', - description: '_id must be a string and is required.', - }, - memberLimit: { - bsonType: 'number', - description: 'memberLimit must be a number and is required.', - }, - name: { - bsonType: 'string', - description: 'name must be a string and is required.', - }, - type: { - bsonType: 'string', - description: 'type must be a string and is required.', - }, - members: { - bsonType: 'array', - description: 'members must be an array and is required.', - items: { - bsonType: 'object', - required: ['user', 'role'], - properties: { - user: { - bsonType: 'string', - description: 'user must be a string and is required.', - }, - role: { - bsonType: 'string', - description: 'role must be a string and is required.', - }, - }, - }, - }, - }, - }, - }, - validationLevel: 'strict', - validationAction: 'error', - }; - yield colecao.createIndex({ user: 1 }); - yield db.command({ - collMod: collection_organizations, - validator: validationRules.validator, - validationLevel: validationRules.validationLevel, - validationAction: validationRules.validationAction, - }); - console.log(`Collection ${collection_organizations} with validation rules created successfully.`); - yield client.close(); - }); -} -exports.createOrganizationCollectionWithValidation = createOrganizationCollectionWithValidation; diff --git a/build/organizations/validationOrgModel.d.ts b/build/organizations/validationOrgModel.d.ts deleted file mode 100644 index 3904cf6..0000000 --- a/build/organizations/validationOrgModel.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IOrganizationDb } from '../interfaces'; -export declare const organizationModel: import("mongoose").Model & IOrganizationDb & Required<{ - _id: string; -}>, any>; diff --git a/build/organizations/validationOrgModel.js b/build/organizations/validationOrgModel.js deleted file mode 100644 index f89227c..0000000 --- a/build/organizations/validationOrgModel.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.organizationModel = void 0; -const mongoose_1 = require("mongoose"); -const organizationSchema = new mongoose_1.Schema({ - _id: { type: String, required: true }, - memberLimit: { type: Number, required: true }, - name: { type: String, required: true }, - type: { type: String, required: true }, - members: [ - { - _id: false, - user: { type: String, required: true, index: true }, - role: { type: String, required: true }, - }, - ], -}); -exports.organizationModel = (0, mongoose_1.model)('organization', organizationSchema); diff --git a/build/projects/services/ProjectService.d.ts b/build/projects/services/ProjectService.d.ts deleted file mode 100644 index 64fd378..0000000 --- a/build/projects/services/ProjectService.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IProjectDb } from '../../interfaces'; -export declare class ProjectService { - protected model: import("mongoose").Model & IProjectDb & Required<{ - _id: string; - }>, any>; - protected configure(): void; - insert(project: IProjectDb): Promise; - get(project_id: string, user_id: string): Promise; - getPopulated(project_id: string, user_id: string): Promise; - update(project: IProjectDb): Promise; - remove(project_id: string, user_id: string): Promise; - removeAllFromUser(user_id: string): Promise; - exists(project_id: string, user_id: string): Promise; - existsWithName(user_id: string, project_name: string): Promise; - listAllFromUser(user_id: string): Promise; - listAllFromUserPopulated(user_id: string): Promise; - listAll(): Promise; -} diff --git a/build/projects/services/ProjectService.js b/build/projects/services/ProjectService.js deleted file mode 100644 index 1616183..0000000 --- a/build/projects/services/ProjectService.js +++ /dev/null @@ -1,156 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ProjectService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const validationProjectsModel_1 = require("../validationProjectsModel"); -const connection_1 = require("../../connection"); -class ProjectService { - constructor() { - this.model = validationProjectsModel_1.projectModel; - } - configure() { } - insert(project) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project_record = new this.model(project); - yield project_record.save(); - return project_record.toJSON(); - }); - } - get(project_id, user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project_record = yield this.model - .findOne({ _id: project_id, user_id: user_id }) - .lean() - .exec(); - if (!project_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; - err.Details = `Project '${project_id}' not found'`; - throw err; - } - return project_record; - }); - } - getPopulated(project_id, user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project_record = yield this.model - .findOne({ _id: project_id, user_id: user_id }) - .populate('clouds') - .populate('bim') - .populate('images') - .lean() - .exec(); - if (!project_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; - err.Details = `Project '${project_id}' not found'`; - throw err; - } - return project_record; - }); - } - update(project) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project_record = yield this.model.findByIdAndUpdate(project._id, project, { - new: true, - }); - if (!project_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; - err.Details = `Project '${project._id}' not found'`; - throw err; - } - return project_record.toJSON(); - }); - } - remove(project_id, user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = yield this.exists(project_id, user_id); - if (!exists) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; - err.Details = `Project '${project_id}' not found'`; - throw err; - } - yield this.model.findByIdAndRemove(project_id); - }); - } - removeAllFromUser(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - yield this.model.deleteMany({ user_id: user_id }); - }); - } - exists(project_id, user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const exists = (yield this.model - .exists({ _id: project_id, user_id: user_id }) - .lean() - .exec()) != null; - return exists; - }); - } - existsWithName(user_id, project_name) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const project = yield this.model - .findOne({ user_id: user_id, name: project_name }) - .lean() - .exec(); - return project != null; - }); - } - listAllFromUser(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const projects = yield this.model - .find({ user_id: user_id }) - .lean() - .exec(); - return projects; - }); - } - listAllFromUserPopulated(user_id) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const projects = yield this.model - .find({ user_id: user_id }) - .populate('clouds') - .populate('bim') - .populate('images') - .lean() - .exec(); - return projects; - }); - } - listAll() { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const projects = yield this.model.find().lean().exec(); - return projects; - }); - } -} -exports.ProjectService = ProjectService; diff --git a/build/projects/validationProjectsDb.d.ts b/build/projects/validationProjectsDb.d.ts deleted file mode 100644 index 036c18b..0000000 --- a/build/projects/validationProjectsDb.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function createProjectCollectionWithValidation(uri: string, databaseName: string, collection_projects: string): Promise; diff --git a/build/projects/validationProjectsDb.js b/build/projects/validationProjectsDb.js deleted file mode 100644 index f44a3f7..0000000 --- a/build/projects/validationProjectsDb.js +++ /dev/null @@ -1,140 +0,0 @@ -"use strict"; -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.createProjectCollectionWithValidation = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -const mongodb_1 = require("mongodb"); -dotenv_1.default.config(); -function createProjectCollectionWithValidation(uri, databaseName, collection_projects) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(uri); - yield client.connect(); - const db = client.db(databaseName); - const colecao = db.collection(collection_projects); - const validationRules = { - validator: { - $jsonSchema: { - bsonType: 'object', - required: [ - '_id', - 'user_id', - 'name', - 'clientName', - 'type', - 'favorite', - 'clouds', - 'images', - 'bim', - 'projectQuota', - 'createdAt', - 'modifiedAt', - 'publicAccessToken', - 'status', - ], - properties: { - _id: { - bsonType: 'string', - description: 'ID do projeto (string)', - }, - user_id: { - bsonType: 'string', - description: 'ID do usuário (string)', - }, - name: { - bsonType: 'string', - description: 'Nome do projeto (string)', - }, - clientName: { - bsonType: 'string', - description: 'Nome do cliente (string)', - }, - type: { - bsonType: 'string', - description: 'Tipo do projeto (string)', - }, - favorite: { - bsonType: 'bool', - description: 'Indicador de favorito (boolean)', - }, - clouds: { - bsonType: 'array', - items: { bsonType: 'string' }, - description: 'Lista de nuvens associadas (array de strings)', - }, - images: { - bsonType: 'array', - items: { bsonType: 'string' }, - description: 'Lista de imagens associadas (array de strings)', - }, - bim: { - bsonType: 'array', - items: { bsonType: 'string' }, - description: 'Lista de modelos BIM associados (array de strings)', - }, - projectQuota: { - bsonType: 'object', - required: [ - 'pointCloudUsedMB', - 'imageUsedMB', - 'BIMUsedMB', - ], - properties: { - pointCloudUsedMB: { - bsonType: 'number', - description: 'Uso de nuvem de pontos (number)', - }, - imageUsedMB: { - bsonType: 'number', - description: 'Uso de tamanho da imagem (number)', - }, - BIMUsedMB: { - bsonType: 'number', - description: 'Uso de tamanho do BIM (number)', - }, - }, - }, - createdAt: { - bsonType: 'number', - description: 'Timestamp de criação (number)', - }, - modifiedAt: { - bsonType: 'number', - description: 'Timestamp de modificação (number)', - }, - publicAccessToken: { - bsonType: 'string', - description: 'Token de acesso público (string)', - }, - status: { - bsonType: 'string', - description: 'Status do projeto (string)', - }, - }, - }, - }, - validationLevel: 'strict', - validationAction: 'error', - }; - yield colecao.createIndex({ user_id: 1 }); - yield db.command({ - collMod: collection_projects, - validator: validationRules.validator, - validationLevel: validationRules.validationLevel, - validationAction: validationRules.validationAction, - }); - console.log(`Collection ${collection_projects} with validation rules created successfully.`); - yield client.close(); - }); -} -exports.createProjectCollectionWithValidation = createProjectCollectionWithValidation; diff --git a/build/projects/validationProjectsModel.d.ts b/build/projects/validationProjectsModel.d.ts deleted file mode 100644 index e24a0ec..0000000 --- a/build/projects/validationProjectsModel.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IProjectDb } from '../interfaces'; -export declare const projectModel: import("mongoose").Model & IProjectDb & Required<{ - _id: string; -}>, any>; diff --git a/build/projects/validationProjectsModel.js b/build/projects/validationProjectsModel.js deleted file mode 100644 index bbfe911..0000000 --- a/build/projects/validationProjectsModel.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.projectModel = void 0; -const mongoose_1 = require("mongoose"); -const projectSchema = new mongoose_1.Schema({ - _id: { type: String, required: true }, - user_id: { type: String, required: true, index: true }, - name: { type: String, required: true }, - clientName: { type: String, required: true }, - type: { type: String, required: true }, - snapshot: { type: String, required: false }, - favorite: { type: Boolean, required: true }, - clouds: { type: [String], default: [], ref: 'entity' }, - images: { type: [String], default: [], ref: 'entity' }, - bim: { type: [String], default: [], ref: 'entity' }, - projectQuota: { - pointCloudUsedMB: { type: Number, required: true }, - imageUsedMB: { type: Number, required: true }, - BIMUsedMB: { type: Number, required: true }, - }, - createdAt: { type: Number, required: true }, - modifiedAt: { type: Number, required: true }, - owner: { type: String, required: false }, - accessType: { type: String, required: false }, - publicAccessToken: { type: String, required: true }, - status: { type: String, required: true }, -}); -exports.projectModel = (0, mongoose_1.model)('project', projectSchema); diff --git a/build/users/services/createUserService.d.ts b/build/users/services/createUserService.d.ts deleted file mode 100644 index 717b62f..0000000 --- a/build/users/services/createUserService.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { IUsers } from '../../interfaces'; -export declare function createUserService(user: IUsers): Promise; diff --git a/build/users/services/createUserService.js b/build/users/services/createUserService.js deleted file mode 100644 index 90d9545..0000000 --- a/build/users/services/createUserService.js +++ /dev/null @@ -1,64 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.createUserService = void 0; -const validationUserModel_1 = require("../validationUserModel"); -const uuid_1 = require("uuid"); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function createUserService(user) { - return __awaiter(this, void 0, void 0, function* () { - try { - const existingUser = yield validationUserModel_1.UserModel.findOne({ email: user.email }); - if (existingUser) { - const err = duna_web_platform_error_defs_1.ErrorMessages.ResourceExists; - throw err; - } - const newUser = new validationUserModel_1.UserModel({ - _id: (0, uuid_1.v4)(), - name: user.name, - lastName: user.lastName, - email: user.email, - password: user.password, - actingField: user.actingField, - phoneNumber: user.phoneNumber, - postalCode: user.postalCode, - useObjective: user.useObjective, - imagePath: user.imagePath, - street: user.street, - number: user.number, - complement: user.complement, - quota: { - BIMSizeQuotaMB: 5000, - pointCloudQuotaMB: 5000, - imageSizeQuotaMB: 5000, - BIMUsedMB: 0, - imageUsedMB: 0, - pointCloudUsedMB: 0, - }, - paymentInfo: { - customerId: user.paymentInfo.customerId, - plan: user.paymentInfo.plan, - expirationDate: user.paymentInfo.expirationDate, - }, - }); - const savedUser = yield newUser.save(); - return savedUser; - } - catch (error) { - if (error !== duna_web_platform_error_defs_1.ErrorMessages.ResourceExists) { - error = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - error.Details = 'Possibly wrong data schema.'; - } - throw error; - } - }); -} -exports.createUserService = createUserService; diff --git a/build/users/services/deleteUserService.d.ts b/build/users/services/deleteUserService.d.ts deleted file mode 100644 index 83f05a5..0000000 --- a/build/users/services/deleteUserService.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -export declare function deleteUserService(userId: string): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ - _id: string; -}>) | null>; diff --git a/build/users/services/deleteUserService.js b/build/users/services/deleteUserService.js deleted file mode 100644 index 097dd49..0000000 --- a/build/users/services/deleteUserService.js +++ /dev/null @@ -1,27 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.deleteUserService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const validationUserModel_1 = require("../validationUserModel"); -function deleteUserService(userId) { - return __awaiter(this, void 0, void 0, function* () { - try { - return yield validationUserModel_1.UserModel.findOneAndDelete({ _id: userId }); - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Internal server Error '; - throw err; - } - }); -} -exports.deleteUserService = deleteUserService; diff --git a/build/users/services/getOneUserService.d.ts b/build/users/services/getOneUserService.d.ts deleted file mode 100644 index 8f7d2e7..0000000 --- a/build/users/services/getOneUserService.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -export declare function getOneUserService(_id: string): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ - _id: string; -}>) | null>; diff --git a/build/users/services/getOneUserService.js b/build/users/services/getOneUserService.js deleted file mode 100644 index 88556cc..0000000 --- a/build/users/services/getOneUserService.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getOneUserService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const validationUserModel_1 = require("../validationUserModel"); -function getOneUserService(_id) { - return __awaiter(this, void 0, void 0, function* () { - try { - const user = yield validationUserModel_1.UserModel.findOne({ _id }); - return user; - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Internal server Error '; - throw err; - } - }); -} -exports.getOneUserService = getOneUserService; diff --git a/build/users/services/getUsersService.d.ts b/build/users/services/getUsersService.d.ts deleted file mode 100644 index 9602c32..0000000 --- a/build/users/services/getUsersService.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -export declare function getUsersService(): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ - _id: string; -}>)[]>; diff --git a/build/users/services/getUsersService.js b/build/users/services/getUsersService.js deleted file mode 100644 index fada50f..0000000 --- a/build/users/services/getUsersService.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getUsersService = void 0; -const validationUserModel_1 = require("../validationUserModel"); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function getUsersService() { - return __awaiter(this, void 0, void 0, function* () { - try { - const user = yield validationUserModel_1.UserModel.find(); - return user; - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Internal server Error '; - throw err; - } - }); -} -exports.getUsersService = getUsersService; diff --git a/build/users/services/loginService.d.ts b/build/users/services/loginService.d.ts deleted file mode 100644 index f30fbd0..0000000 --- a/build/users/services/loginService.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { IUsers } from '../../interfaces'; -export declare function getUserByEmail(email: string): Promise; diff --git a/build/users/services/loginService.js b/build/users/services/loginService.js deleted file mode 100644 index b90a214..0000000 --- a/build/users/services/loginService.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getUserByEmail = void 0; -const validationUserModel_1 = require("../validationUserModel"); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function getUserByEmail(email) { - return __awaiter(this, void 0, void 0, function* () { - try { - const user = yield validationUserModel_1.UserModel.findOne({ email }).exec(); - return user; - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Internal server Error '; - throw err; - } - }); -} -exports.getUserByEmail = getUserByEmail; diff --git a/build/users/services/updateCustomerIdService.d.ts b/build/users/services/updateCustomerIdService.d.ts deleted file mode 100644 index 396e353..0000000 --- a/build/users/services/updateCustomerIdService.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { IUsers } from '../../interfaces'; -export declare function updateCustomerId(email: string, updates: Partial): Promise; diff --git a/build/users/services/updateCustomerIdService.js b/build/users/services/updateCustomerIdService.js deleted file mode 100644 index 5bc21f0..0000000 --- a/build/users/services/updateCustomerIdService.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.updateCustomerId = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const validationUserModel_1 = require("../validationUserModel"); -function updateCustomerId(email, updates) { - return __awaiter(this, void 0, void 0, function* () { - try { - const existingUser = yield validationUserModel_1.UserModel.findOne({ email: email }); - if (!existingUser) { - return null; - } - if (updates.customerId) { - existingUser.customerId = updates.customerId; - } - if (updates.paymentInfo) { - const paymentInfoUpdates = updates.paymentInfo; - if (paymentInfoUpdates.customerId) { - existingUser.paymentInfo.customerId = paymentInfoUpdates.customerId; - } - if (paymentInfoUpdates.plan) { - existingUser.paymentInfo.plan = paymentInfoUpdates.plan; - } - if (paymentInfoUpdates.expirationDate) { - existingUser.paymentInfo.expirationDate = paymentInfoUpdates.expirationDate; - } - } - yield existingUser.save(); - return existingUser; - } - catch (error) { - console.error('Error in updateUserService:', error); - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Error updating user data.'; - throw err; - } - }); -} -exports.updateCustomerId = updateCustomerId; diff --git a/build/users/services/updateUserService.d.ts b/build/users/services/updateUserService.d.ts deleted file mode 100644 index cc3e1e3..0000000 --- a/build/users/services/updateUserService.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { IUsers } from '../../interfaces'; -export declare function updateUserService(userId: string, updates: Partial): Promise; diff --git a/build/users/services/updateUserService.js b/build/users/services/updateUserService.js deleted file mode 100644 index b284704..0000000 --- a/build/users/services/updateUserService.js +++ /dev/null @@ -1,58 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.updateUserService = void 0; -const validationUserModel_1 = require("../validationUserModel"); -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -function updateUserService(userId, updates) { - return __awaiter(this, void 0, void 0, function* () { - try { - const existingUser = yield validationUserModel_1.UserModel.findById(userId); - if (!existingUser) { - return null; - } - if (updates.name) - existingUser.name = updates.name; - if (updates.lastName) - existingUser.lastName = updates.lastName; - if (updates.email) - existingUser.email = updates.email; - if (updates.password) - existingUser.password = updates.password; - if (updates.actingField) - existingUser.actingField = updates.actingField; - if (updates.phoneNumber) - existingUser.phoneNumber = updates.phoneNumber; - if (updates.postalCode) - existingUser.postalCode = updates.postalCode; - if (updates.useObjective) - existingUser.useObjective = updates.useObjective; - if (updates.imagePath) - existingUser.imagePath = updates.imagePath; - if (updates.street) - existingUser.street = updates.street; - if (updates.number) - existingUser.number = updates.number; - if (updates.complement) - existingUser.complement = updates.complement; - if (updates.quota) - existingUser.quota = updates.quota; - yield existingUser.save(); - return existingUser; - } - catch (error) { - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = 'Error updating user data.'; - throw err; - } - }); -} -exports.updateUserService = updateUserService; diff --git a/build/users/validationDbUsers.d.ts b/build/users/validationDbUsers.d.ts deleted file mode 100644 index a5d5f32..0000000 --- a/build/users/validationDbUsers.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function createUserCollectionWithValidation(uri: string, databaseName: string, collectionName: string): Promise; diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js deleted file mode 100644 index fe39caf..0000000 --- a/build/users/validationDbUsers.js +++ /dev/null @@ -1,121 +0,0 @@ -"use strict"; -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.createUserCollectionWithValidation = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -const mongodb_1 = require("mongodb"); -dotenv_1.default.config(); -function createUserCollectionWithValidation(uri, databaseName, collectionName) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(uri); - yield client.connect(); - const db = client.db(databaseName); - const colecao = db.collection(collectionName); - const validationRules = { - validator: { - $jsonSchema: { - bsonType: 'object', - required: [ - 'name', - 'lastName', - 'password', - 'postalCode', - 'street', - 'number', - 'quota', - ], - properties: { - name: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - lastName: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - password: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - postalCode: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - street: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - number: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - complement: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - quota: { - bsonType: 'object', - required: [ - 'pointCloudQuotaMB', - 'imageSizeQuotaMB', - 'BIMSizeQuotaMB', - 'pointCloudUsedMB', - 'imageUsedMB', - 'BIMUsedMB', - ], - properties: { - pointCloudQuotaMB: { - bsonType: 'number', - description: 'Quota para nuvem de pontos (number)', - }, - imageSizeQuotaMB: { - bsonType: 'number', - description: 'Quota para tamanho da imagem (number)', - }, - BIMSizeQuotaMB: { - bsonType: 'number', - description: 'Quota para tamanho do BIM (number)', - }, - pointCloudUsedMB: { - bsonType: 'number', - description: 'Uso de nuvem de pontos (number)', - }, - imageUsedMB: { - bsonType: 'number', - description: 'Uso de tamanho da imagem (number)', - }, - BIMUsedMB: { - bsonType: 'number', - description: 'Uso de tamanho do BIM (number)', - }, - }, - }, - }, - }, - }, - validationLevel: 'strict', - validationAction: 'error', - }; - yield colecao.createIndex({ _id: 1 }); - yield db.command({ - collMod: colecao.collectionName, - validator: validationRules.validator, - validationLevel: validationRules.validationLevel, - validationAction: validationRules.validationAction, - }); - console.log(`Coleção ${collectionName} com regras de validação criada com sucesso.`); - yield client.close(); - }); -} -exports.createUserCollectionWithValidation = createUserCollectionWithValidation; diff --git a/build/users/validationUserModel.d.ts b/build/users/validationUserModel.d.ts deleted file mode 100644 index 86c6c19..0000000 --- a/build/users/validationUserModel.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Model } from 'mongoose'; -import { IUsers } from '../interfaces'; -declare const UserModel: Model; -export { UserModel }; diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js deleted file mode 100644 index 76ac5dd..0000000 --- a/build/users/validationUserModel.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.UserModel = void 0; -const mongoose_1 = __importDefault(require("mongoose")); -const UserSchema = new mongoose_1.default.Schema({ - _id: { type: String, required: true }, - name: { type: String, required: true }, - lastName: { type: String, required: true }, - email: { type: String, unique: true }, - password: { type: String, required: true }, - actingField: { type: String, default: '' }, - phoneNumber: { type: String, default: '' }, - postalCode: { type: String, required: true, default: '' }, - useObjective: { type: String, default: '' }, - imagePath: { type: String, default: '' }, - street: { type: String, required: true, default: '' }, - number: { type: String, required: true, default: '' }, - complement: { type: String, default: '' }, - quota: { - pointCloudQuotaMB: { type: Number, required: true }, - imageSizeQuotaMB: { type: Number, required: true }, - BIMSizeQuotaMB: { type: Number, required: true }, - pointCloudUsedMB: { type: Number, required: true }, - imageUsedMB: { type: Number, required: true }, - BIMUsedMB: { type: Number, required: true }, - }, - paymentInfo: { - customerId: { type: String, required: false, default: '' }, - plan: { type: String, required: false, default: '' }, - expirationDate: { type: String, required: false, default: '' }, - }, - customerId: { type: String, required: false }, - validatedMail: { type: Boolean, required: true, default: false }, -}); -const UserModel = mongoose_1.default.model('user', UserSchema); -exports.UserModel = UserModel; diff --git a/build/usersProject/UserService.d.ts b/build/usersProject/UserService.d.ts deleted file mode 100644 index 3774e0f..0000000 --- a/build/usersProject/UserService.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -import { IUsers } from '../interfaces'; -export declare class UserService { - protected model: import("mongoose").Model & IUsers & Required<{ - _id: string; - }>, any>; - protected configure(): void; - get(user_id?: string, email?: string): Promise; - update(user: IUsers): Promise; -} diff --git a/build/usersProject/UserService.js b/build/usersProject/UserService.js deleted file mode 100644 index ec1a453..0000000 --- a/build/usersProject/UserService.js +++ /dev/null @@ -1,57 +0,0 @@ -"use strict"; -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()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.UserService = void 0; -const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); -const connection_1 = require("../connection"); -const validationUserModel_1 = require("../users/validationUserModel"); -class UserService { - constructor() { - this.model = validationUserModel_1.UserModel; - } - configure() { } - get(user_id, email) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - let user; - if (user_id) { - user = yield this.model.findById(user_id).lean().exec(); - } - else { - user = yield this.model.findOne({ email: email }).lean().exec(); - } - if (!user) { - const id = user_id ? user_id : email; - const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; - err.Details = `User ${id} not found`; - throw err; - } - return user; - }); - } - update(user) { - return __awaiter(this, void 0, void 0, function* () { - //Check if mongoDB is connected - (0, connection_1.checkConnectionStatus)(); - const user_record = yield this.model.findByIdAndUpdate(user._id, user, { - new: true, - }); - if (!user_record) { - const err = duna_web_platform_error_defs_1.ErrorMessages.UserNotFound; - err.Details = `User '${user._id}' not found'`; - throw err; - } - return user_record.toJSON(); - }); - } -} -exports.UserService = UserService; diff --git a/src/users/services/updateCustomerIdService.ts b/src/users/services/updateCustomerIdService.ts index 80662a3..a09f147 100644 --- a/src/users/services/updateCustomerIdService.ts +++ b/src/users/services/updateCustomerIdService.ts @@ -5,39 +5,33 @@ import { UserModel } from '../validationUserModel' export async function updateCustomerId( email: string, - updates: Partial -): Promise { + updates: Partial + ): Promise { try { - const existingUser = await UserModel.findOne({ email: email }); - - if (!existingUser) { - return null; - } - - if (updates.customerId) { - existingUser.customerId = updates.customerId; - } - - if (updates.paymentInfo) { - const paymentInfoUpdates = updates.paymentInfo; - if (paymentInfoUpdates.customerId) { - existingUser.paymentInfo.customerId = paymentInfoUpdates.customerId; - } - if (paymentInfoUpdates.plan) { - existingUser.paymentInfo.plan = paymentInfoUpdates.plan; - } - if (paymentInfoUpdates.expirationDate) { - existingUser.paymentInfo.expirationDate = paymentInfoUpdates.expirationDate; - } - } - - await existingUser.save(); - - return existingUser; - } catch (error) { - console.error('Error in updateUserService:', error); - const err = ErrorMessages.InternalServerError; - err.Details = 'Error updating user data.'; + const filter = { email }; + const update = { + $set: { + 'paymentInfo.customerId': updates.customerId, + 'paymentInfo.plan': updates.plan, + 'paymentInfo.expirationDate': updates.expirationDate, + }, + }; + + const options = { new: true }; + + const updatedUser = await UserModel.findOneAndUpdate(filter, update, options); + + if (!updatedUser) { + const err = ErrorMessages.UserNotFound.Message throw err; + } + + return updatedUser; + } catch (error) { + console.error('Error in updateCustomerId:', error); + const err = ErrorMessages.InternalServerError; + err.Details = 'Error updating user data.'; + throw err; } -} \ No newline at end of file + } + \ No newline at end of file From 3beadf8e81be2a3ee2dbc477d3c62aaef50816c1 Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 20:28:25 -0300 Subject: [PATCH 12/20] fix:refactor updateCustomerId --- build/connection.d.ts | 3 + build/connection.js | 50 +++++ build/entity/services/EntityService.d.ts | 58 ++++++ build/entity/services/EntityService.js | 173 ++++++++++++++++++ build/entity/validationEntityDb.d.ts | 1 + build/entity/validationEntityDb.js | 83 +++++++++ build/entity/validationEntityModel.d.ts | 29 +++ build/entity/validationEntityModel.js | 15 ++ build/index.d.ts | 25 +++ build/index.js | 45 +++++ build/interfaces.d.ts | 113 ++++++++++++ build/interfaces.js | 32 ++++ .../services/OrganizationService.d.ts | 39 ++++ .../services/OrganizationService.js | 118 ++++++++++++ build/organizations/validationOrgDb.d.ts | 1 + build/organizations/validationOrgDb.js | 82 +++++++++ build/organizations/validationOrgModel.d.ts | 29 +++ build/organizations/validationOrgModel.js | 18 ++ build/projects/services/ProjectService.d.ts | 43 +++++ build/projects/services/ProjectService.js | 156 ++++++++++++++++ build/projects/validationProjectsDb.d.ts | 1 + build/projects/validationProjectsDb.js | 140 ++++++++++++++ build/projects/validationProjectsModel.d.ts | 29 +++ build/projects/validationProjectsModel.js | 28 +++ build/users/services/createUserService.d.ts | 2 + build/users/services/createUserService.js | 64 +++++++ build/users/services/deleteUserService.d.ts | 28 +++ build/users/services/deleteUserService.js | 27 +++ build/users/services/getOneUserService.d.ts | 28 +++ build/users/services/getOneUserService.js | 28 +++ build/users/services/getUsersService.d.ts | 28 +++ build/users/services/getUsersService.js | 28 +++ build/users/services/loginService.d.ts | 2 + build/users/services/loginService.js | 28 +++ .../services/updateCustomerIdService.d.ts | 2 + .../users/services/updateCustomerIdService.js | 42 +++++ build/users/services/updateUserService.d.ts | 2 + build/users/services/updateUserService.js | 58 ++++++ build/users/validationDbUsers.d.ts | 1 + build/users/validationDbUsers.js | 121 ++++++++++++ build/users/validationUserModel.d.ts | 4 + build/users/validationUserModel.js | 39 ++++ build/usersProject/UserService.d.ts | 34 ++++ build/usersProject/UserService.js | 57 ++++++ 44 files changed, 1934 insertions(+) create mode 100644 build/connection.d.ts create mode 100644 build/connection.js create mode 100644 build/entity/services/EntityService.d.ts create mode 100644 build/entity/services/EntityService.js create mode 100644 build/entity/validationEntityDb.d.ts create mode 100644 build/entity/validationEntityDb.js create mode 100644 build/entity/validationEntityModel.d.ts create mode 100644 build/entity/validationEntityModel.js create mode 100644 build/index.d.ts create mode 100644 build/index.js create mode 100644 build/interfaces.d.ts create mode 100644 build/interfaces.js create mode 100644 build/organizations/services/OrganizationService.d.ts create mode 100644 build/organizations/services/OrganizationService.js create mode 100644 build/organizations/validationOrgDb.d.ts create mode 100644 build/organizations/validationOrgDb.js create mode 100644 build/organizations/validationOrgModel.d.ts create mode 100644 build/organizations/validationOrgModel.js create mode 100644 build/projects/services/ProjectService.d.ts create mode 100644 build/projects/services/ProjectService.js create mode 100644 build/projects/validationProjectsDb.d.ts create mode 100644 build/projects/validationProjectsDb.js create mode 100644 build/projects/validationProjectsModel.d.ts create mode 100644 build/projects/validationProjectsModel.js create mode 100644 build/users/services/createUserService.d.ts create mode 100644 build/users/services/createUserService.js create mode 100644 build/users/services/deleteUserService.d.ts create mode 100644 build/users/services/deleteUserService.js create mode 100644 build/users/services/getOneUserService.d.ts create mode 100644 build/users/services/getOneUserService.js create mode 100644 build/users/services/getUsersService.d.ts create mode 100644 build/users/services/getUsersService.js create mode 100644 build/users/services/loginService.d.ts create mode 100644 build/users/services/loginService.js create mode 100644 build/users/services/updateCustomerIdService.d.ts create mode 100644 build/users/services/updateCustomerIdService.js create mode 100644 build/users/services/updateUserService.d.ts create mode 100644 build/users/services/updateUserService.js create mode 100644 build/users/validationDbUsers.d.ts create mode 100644 build/users/validationDbUsers.js create mode 100644 build/users/validationUserModel.d.ts create mode 100644 build/users/validationUserModel.js create mode 100644 build/usersProject/UserService.d.ts create mode 100644 build/usersProject/UserService.js diff --git a/build/connection.d.ts b/build/connection.d.ts new file mode 100644 index 0000000..5edda3e --- /dev/null +++ b/build/connection.d.ts @@ -0,0 +1,3 @@ +export declare function connectToDatabase(url: string, databaseName: string): Promise; +export declare function checkConnectionStatus(): void; +export declare function subscribeToDatabaseEvents(): void; diff --git a/build/connection.js b/build/connection.js new file mode 100644 index 0000000..560ad28 --- /dev/null +++ b/build/connection.js @@ -0,0 +1,50 @@ +"use strict"; +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.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = void 0; +const mongoose_1 = __importDefault(require("mongoose")); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function connectToDatabase(url, databaseName) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield mongoose_1.default.connect(`${url}/${databaseName}`, {}); + console.log(`Conectado ao banco de dados: ${databaseName}`); + } + catch (error) { + throw error; + } + }); +} +exports.connectToDatabase = connectToDatabase; +function checkConnectionStatus() { + // 1 -> Connected + if (mongoose_1.default.connection.readyState != 1) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = `MongoDB disconnected`; + throw err; + } +} +exports.checkConnectionStatus = checkConnectionStatus; +function subscribeToDatabaseEvents() { + mongoose_1.default.connection.on('connected', () => { + console.log(`⚡️[database]: MongoDB connected`); + }); + mongoose_1.default.connection.on('error', (error) => { + console.log(`⚡️[database]: MongoDB Error - ${error}`); + }); + mongoose_1.default.connection.on('disconnected', () => { + console.log(`⚡️[database]: MongoDB Disconnected`); + }); +} +exports.subscribeToDatabaseEvents = subscribeToDatabaseEvents; diff --git a/build/entity/services/EntityService.d.ts b/build/entity/services/EntityService.d.ts new file mode 100644 index 0000000..1cfec63 --- /dev/null +++ b/build/entity/services/EntityService.d.ts @@ -0,0 +1,58 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IEntityDb } from '../../interfaces'; +export declare class EntityService { + protected model: import("mongoose").Model & IEntityDb & Required<{ + _id: string; + }>, any>; + protected configure(): void; + insert(entity: IEntityDb): Promise; + get(entity_id: string): Promise; + getByName(project_id: string, entity_name: string): Promise; + update(entity: IEntityDb): Promise; + remove(entity_id: string): Promise; + removeAllFromUser(user_id: string): Promise; + exists(entity_id: string): Promise; + existsWithName(project_id: string, entity_name: string): Promise; + listAllFromProject(project_id: string): Promise; + /** + * Assign a parent entity to another entity. This essentially + * makes them a `child` entity. Child entities are not allowed + * to be processed. (business logic) + * + * @param project_id + * @param entity_name + * @param parent_entity_name + */ + assignParentName(project_id: string, entity_name: string, parent_entity_name: string): Promise; + /** + * Promote entity. Removes the parent field and allows them to be processed + * (business logic) + * @param project_id + * @param entity_name + */ + promoteEntity(project_id: string, entity_name: string): Promise; +} diff --git a/build/entity/services/EntityService.js b/build/entity/services/EntityService.js new file mode 100644 index 0000000..1e4da80 --- /dev/null +++ b/build/entity/services/EntityService.js @@ -0,0 +1,173 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.EntityService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const connection_1 = require("../../connection"); +const validationEntityModel_1 = require("../validationEntityModel"); +class EntityService { + constructor() { + this.model = validationEntityModel_1.entityModel; + } + configure() { } + insert(entity) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entity_record = new this.model(entity); + yield entity_record.save(); + return entity_record.toJSON(); + }); + } + get(entity_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entity_record = yield this.model.findById(entity_id).lean().exec(); + if (!entity_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + throw err; + } + return entity_record; + }); + } + getByName(project_id, entity_name) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entity_record = yield this.model + .findOne({ projectId: project_id, name: entity_name }) + .lean() + .exec(); + if (!entity_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + throw err; + } + return entity_record; + }); + } + update(entity) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entity_record = yield this.model + .findByIdAndUpdate(entity._id, entity, { + new: true, + }) + .lean() + .exec(); + if (!entity_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + throw err; + } + return entity_record; + }); + } + remove(entity_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = yield this.exists(entity_id); + if (!exists) { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + throw err; + } + yield this.model.findByIdAndRemove(entity_id); + }); + } + removeAllFromUser(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + yield this.model.deleteMany({ user_id: user_id }); + }); + } + exists(entity_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = (yield this.model.exists({ _id: entity_id }).lean().exec()) != null; + return exists; + }); + } + existsWithName(project_id, entity_name) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project = yield this.model + .findOne({ projectId: project_id, name: entity_name }) + .lean() + .exec(); + return project != null; + }); + } + listAllFromProject(project_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const entities = yield this.model + .find({ proje: project_id }) + .lean() + .exec(); + return entities; + }); + } + /** + * Assign a parent entity to another entity. This essentially + * makes them a `child` entity. Child entities are not allowed + * to be processed. (business logic) + * + * @param project_id + * @param entity_name + * @param parent_entity_name + */ + assignParentName(project_id, entity_name, parent_entity_name) { + return __awaiter(this, void 0, void 0, function* () { + // Check if entity exist. + const child_entity = yield this.getByName(project_id, entity_name); + if (!(yield this.existsWithName(project_id, parent_entity_name))) { + { + const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist; + err.Details = `Parent Name: ${parent_entity_name}`; + throw err; + } + } + child_entity.parentName = parent_entity_name; + this.update(child_entity); + }); + } + /** + * Promote entity. Removes the parent field and allows them to be processed + * (business logic) + * @param project_id + * @param entity_name + */ + promoteEntity(project_id, entity_name) { + return __awaiter(this, void 0, void 0, function* () { + // Check if entity exist. + const child_entity = yield this.getByName(project_id, entity_name); + if (child_entity.parentName === undefined) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = + 'Entity is not a chilld, or does not have parent property.'; + throw err; + } + const entity = yield this.model.findOne({ + projectId: project_id, + name: entity_name, + }); + // Assigning document properties to undefined removes them. + entity.parentName = undefined; + yield entity.save(); + }); + } +} +exports.EntityService = EntityService; diff --git a/build/entity/validationEntityDb.d.ts b/build/entity/validationEntityDb.d.ts new file mode 100644 index 0000000..666cb38 --- /dev/null +++ b/build/entity/validationEntityDb.d.ts @@ -0,0 +1 @@ +export declare function createEntityCollectionWithValidation(uri: string, databaseName: string, collectionName: string): Promise; diff --git a/build/entity/validationEntityDb.js b/build/entity/validationEntityDb.js new file mode 100644 index 0000000..04c8ee6 --- /dev/null +++ b/build/entity/validationEntityDb.js @@ -0,0 +1,83 @@ +"use strict"; +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.createEntityCollectionWithValidation = void 0; +const dotenv_1 = __importDefault(require("dotenv")); +const mongodb_1 = require("mongodb"); +dotenv_1.default.config(); +function createEntityCollectionWithValidation(uri, databaseName, collectionName) { + return __awaiter(this, void 0, void 0, function* () { + const client = new mongodb_1.MongoClient(uri); + yield client.connect(); + const db = client.db(databaseName); + const colecao = db.collection(collectionName); + const validationRules = { + validator: { + $jsonSchema: { + bsonType: 'object', + required: [ + 'projectId', + 'type', + 'name', + 'location', + 'sizeMB', + 'shareGroup', + ], + properties: { + projectId: { + bsonType: 'string', + description: 'Project ID must be a string and is required.', + }, + type: { + bsonType: 'string', + description: 'Type must be a string and is required.', + }, + name: { + bsonType: 'string', + description: 'Name must be a string and is required.', + }, + location: { + bsonType: 'string', + description: 'Location must be a string and is required.', + }, + sizeMB: { + bsonType: 'number', + description: 'SizeMB must be a number and is required.', + }, + shareGroup: { + bsonType: 'string', + description: 'Share group must be a string and is required.', + }, + parentName: { + bsonType: 'string', + description: 'Holds a name reference to a parent entity. Not required.', + }, + }, + }, + }, + validationLevel: 'strict', + validationAction: 'error', + }; + yield colecao.createIndex({ projectId: 1 }); + yield db.command({ + collMod: colecao.collectionName, + validator: validationRules.validator, + validationLevel: validationRules.validationLevel, + validationAction: validationRules.validationAction, + }); + console.log(`Collection ${collectionName} with validation rules created successfully.`); + yield client.close(); + }); +} +exports.createEntityCollectionWithValidation = createEntityCollectionWithValidation; diff --git a/build/entity/validationEntityModel.d.ts b/build/entity/validationEntityModel.d.ts new file mode 100644 index 0000000..1a56a9c --- /dev/null +++ b/build/entity/validationEntityModel.d.ts @@ -0,0 +1,29 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IEntityDb } from '../interfaces'; +export declare const entityModel: import("mongoose").Model & IEntityDb & Required<{ + _id: string; +}>, any>; diff --git a/build/entity/validationEntityModel.js b/build/entity/validationEntityModel.js new file mode 100644 index 0000000..ee39e35 --- /dev/null +++ b/build/entity/validationEntityModel.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.entityModel = void 0; +const mongoose_1 = require("mongoose"); +const entitySchema = new mongoose_1.Schema({ + _id: { type: String, required: true }, + projectId: { type: String, required: true, index: true }, + type: { type: String, required: true }, + name: { type: String, required: true }, + location: { type: String, required: true }, + sizeMB: { type: Number, required: true }, + shareGroup: { type: String, required: true }, + parentName: { type: String, requred: false }, +}); +exports.entityModel = (0, mongoose_1.model)('entity', entitySchema); diff --git a/build/index.d.ts b/build/index.d.ts new file mode 100644 index 0000000..c25ed8e --- /dev/null +++ b/build/index.d.ts @@ -0,0 +1,25 @@ +import { createUserCollectionWithValidation } from './users/validationDbUsers'; +import { UserModel } from './users/validationUserModel'; +import { IMemberDb, IUser, IUsers } from './interfaces'; +import { connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents } from './connection'; +import { IEntityDb } from './interfaces'; +import { IProjectDb } from './interfaces'; +import { IOrganizationDb } from './interfaces'; +import { entityModel } from './entity/validationEntityModel'; +import { projectModel } from './projects/validationProjectsModel'; +import { organizationModel } from './organizations/validationOrgModel'; +import { createEntityCollectionWithValidation } from './entity/validationEntityDb'; +import { createProjectCollectionWithValidation } from './projects/validationProjectsDb'; +import { createOrganizationCollectionWithValidation } from './organizations/validationOrgDb'; +import { createUserService } from './users/services/createUserService'; +import { getUserByEmail } from './users/services/loginService'; +import { deleteUserService } from './users/services/deleteUserService'; +import { getOneUserService } from './users/services/getOneUserService'; +import { getUsersService } from './users/services/getUsersService'; +import { EntityService } from './entity/services/EntityService'; +import { ProjectService } from './projects/services/ProjectService'; +import { OrganizationService } from './organizations/services/OrganizationService'; +import { updateUserService } from './users/services/updateUserService'; +import { UserService } from './usersProject/UserService'; +import { updateCustomerId } from './users/services/updateCustomerIdService'; +export { createUserCollectionWithValidation, connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents, createEntityCollectionWithValidation, createProjectCollectionWithValidation, createOrganizationCollectionWithValidation, deleteUserService, getOneUserService, getUsersService, createUserService, updateUserService, getUserByEmail, updateCustomerId, UserService, OrganizationService, EntityService, ProjectService, UserModel, entityModel, organizationModel, IUsers, IUser, IEntityDb, IProjectDb, projectModel, IOrganizationDb, IMemberDb, }; diff --git a/build/index.js b/build/index.js new file mode 100644 index 0000000..ac81097 --- /dev/null +++ b/build/index.js @@ -0,0 +1,45 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.projectModel = exports.organizationModel = exports.entityModel = exports.UserModel = exports.ProjectService = exports.EntityService = exports.OrganizationService = exports.UserService = exports.updateCustomerId = exports.getUserByEmail = exports.updateUserService = exports.createUserService = exports.getUsersService = exports.getOneUserService = exports.deleteUserService = exports.createOrganizationCollectionWithValidation = exports.createProjectCollectionWithValidation = exports.createEntityCollectionWithValidation = exports.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = exports.createUserCollectionWithValidation = void 0; +const validationDbUsers_1 = require("./users/validationDbUsers"); +Object.defineProperty(exports, "createUserCollectionWithValidation", { enumerable: true, get: function () { return validationDbUsers_1.createUserCollectionWithValidation; } }); +const validationUserModel_1 = require("./users/validationUserModel"); +Object.defineProperty(exports, "UserModel", { enumerable: true, get: function () { return validationUserModel_1.UserModel; } }); +const connection_1 = require("./connection"); +Object.defineProperty(exports, "connectToDatabase", { enumerable: true, get: function () { return connection_1.connectToDatabase; } }); +Object.defineProperty(exports, "checkConnectionStatus", { enumerable: true, get: function () { return connection_1.checkConnectionStatus; } }); +Object.defineProperty(exports, "subscribeToDatabaseEvents", { enumerable: true, get: function () { return connection_1.subscribeToDatabaseEvents; } }); +const validationEntityModel_1 = require("./entity/validationEntityModel"); +Object.defineProperty(exports, "entityModel", { enumerable: true, get: function () { return validationEntityModel_1.entityModel; } }); +const validationProjectsModel_1 = require("./projects/validationProjectsModel"); +Object.defineProperty(exports, "projectModel", { enumerable: true, get: function () { return validationProjectsModel_1.projectModel; } }); +const validationOrgModel_1 = require("./organizations/validationOrgModel"); +Object.defineProperty(exports, "organizationModel", { enumerable: true, get: function () { return validationOrgModel_1.organizationModel; } }); +const validationEntityDb_1 = require("./entity/validationEntityDb"); +Object.defineProperty(exports, "createEntityCollectionWithValidation", { enumerable: true, get: function () { return validationEntityDb_1.createEntityCollectionWithValidation; } }); +const validationProjectsDb_1 = require("./projects/validationProjectsDb"); +Object.defineProperty(exports, "createProjectCollectionWithValidation", { enumerable: true, get: function () { return validationProjectsDb_1.createProjectCollectionWithValidation; } }); +const validationOrgDb_1 = require("./organizations/validationOrgDb"); +Object.defineProperty(exports, "createOrganizationCollectionWithValidation", { enumerable: true, get: function () { return validationOrgDb_1.createOrganizationCollectionWithValidation; } }); +const createUserService_1 = require("./users/services/createUserService"); +Object.defineProperty(exports, "createUserService", { enumerable: true, get: function () { return createUserService_1.createUserService; } }); +const loginService_1 = require("./users/services/loginService"); +Object.defineProperty(exports, "getUserByEmail", { enumerable: true, get: function () { return loginService_1.getUserByEmail; } }); +const deleteUserService_1 = require("./users/services/deleteUserService"); +Object.defineProperty(exports, "deleteUserService", { enumerable: true, get: function () { return deleteUserService_1.deleteUserService; } }); +const getOneUserService_1 = require("./users/services/getOneUserService"); +Object.defineProperty(exports, "getOneUserService", { enumerable: true, get: function () { return getOneUserService_1.getOneUserService; } }); +const getUsersService_1 = require("./users/services/getUsersService"); +Object.defineProperty(exports, "getUsersService", { enumerable: true, get: function () { return getUsersService_1.getUsersService; } }); +const EntityService_1 = require("./entity/services/EntityService"); +Object.defineProperty(exports, "EntityService", { enumerable: true, get: function () { return EntityService_1.EntityService; } }); +const ProjectService_1 = require("./projects/services/ProjectService"); +Object.defineProperty(exports, "ProjectService", { enumerable: true, get: function () { return ProjectService_1.ProjectService; } }); +const OrganizationService_1 = require("./organizations/services/OrganizationService"); +Object.defineProperty(exports, "OrganizationService", { enumerable: true, get: function () { return OrganizationService_1.OrganizationService; } }); +const updateUserService_1 = require("./users/services/updateUserService"); +Object.defineProperty(exports, "updateUserService", { enumerable: true, get: function () { return updateUserService_1.updateUserService; } }); +const UserService_1 = require("./usersProject/UserService"); +Object.defineProperty(exports, "UserService", { enumerable: true, get: function () { return UserService_1.UserService; } }); +const updateCustomerIdService_1 = require("./users/services/updateCustomerIdService"); +Object.defineProperty(exports, "updateCustomerId", { enumerable: true, get: function () { return updateCustomerIdService_1.updateCustomerId; } }); diff --git a/build/interfaces.d.ts b/build/interfaces.d.ts new file mode 100644 index 0000000..f6e77be --- /dev/null +++ b/build/interfaces.d.ts @@ -0,0 +1,113 @@ +export interface IUsers { + _id: string; + name: string; + lastName: string; + email: string; + password: string; + actingField: string; + phoneNumber: string; + postalCode: string; + useObjective: string; + imagePath: string; + cep: string; + street: string; + number: string; + complement: string; + quota: UserQuota; + validatedMail: boolean; + paymentInfo: { + customerId: string; + plan: string; + expirationDate: Date; + }; + [key: string]: any; +} +export interface IEntityDb { + _id: string; + projectId: string; + type: EntityType; + name: string; + location: string; + sizeMB: number; + shareGroup: ShareGroupType; + parentName?: string; +} +/** + * Project level quota. Contains summed up entity sized. + */ +export interface ProjectQuota { + pointCloudUsedMB: number; + imageUsedMB: number; + BIMUsedMB: number; +} +/** + * User level quota. Contains quota and used space from all projects. + */ +export interface UserQuota { + pointCloudQuotaMB: number; + imageSizeQuotaMB: number; + BIMSizeQuotaMB: number; + pointCloudUsedMB: number; + imageUsedMB: number; + BIMUsedMB: number; +} +export interface IProjectDb { + _id: string; + user_id: string; + name: string; + clientName: string; + type: string; + snapshot?: string; + favorite: boolean; + clouds: Array; + images: Array; + bim: Array; + projectQuota: ProjectQuota; + createdAt: number; + modifiedAt: number; + publicAccessToken: string; + status: ProjectStatus; + owner?: string; + accessType?: ProjectAccessType; +} +export interface IOrganizationDb { + _id: string; + memberLimit: number; + members: Array; + name: string; + type: string; +} +export interface IMemberDb { + user: string; + role: OrganizationMemberRole; +} +export interface IUser { + _id: string; + name: string; + lastName: string; + email: string; +} +export declare enum OrganizationMemberRole { + VIEWER = "VIEWER", + EDITOR = "EDITOR", + ADMIN = "ADMIN", + OWNER = "OWNER" +} +export declare enum ProjectStatus { + IN_PROGRESS = "IN_PROGRESS", + FINISHED = "FINISHED" +} +export declare enum ProjectAccessType { + INTERNAL = "INTERNAL", + PRIVATE = "PRIVATE" +} +export declare enum ShareGroupType { + Public = "public", + Private = "private" +} +export declare enum EntityType { + PointCloud = "clouds", + Image = "images", + BIM = "bim", + Unknown = "unknown" +} diff --git a/build/interfaces.js b/build/interfaces.js new file mode 100644 index 0000000..21cd19e --- /dev/null +++ b/build/interfaces.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.EntityType = exports.ShareGroupType = exports.ProjectAccessType = exports.ProjectStatus = exports.OrganizationMemberRole = void 0; +var OrganizationMemberRole; +(function (OrganizationMemberRole) { + OrganizationMemberRole["VIEWER"] = "VIEWER"; + OrganizationMemberRole["EDITOR"] = "EDITOR"; + OrganizationMemberRole["ADMIN"] = "ADMIN"; + OrganizationMemberRole["OWNER"] = "OWNER"; +})(OrganizationMemberRole || (exports.OrganizationMemberRole = OrganizationMemberRole = {})); +var ProjectStatus; +(function (ProjectStatus) { + ProjectStatus["IN_PROGRESS"] = "IN_PROGRESS"; + ProjectStatus["FINISHED"] = "FINISHED"; +})(ProjectStatus || (exports.ProjectStatus = ProjectStatus = {})); +var ProjectAccessType; +(function (ProjectAccessType) { + ProjectAccessType["INTERNAL"] = "INTERNAL"; + ProjectAccessType["PRIVATE"] = "PRIVATE"; +})(ProjectAccessType || (exports.ProjectAccessType = ProjectAccessType = {})); +var ShareGroupType; +(function (ShareGroupType) { + ShareGroupType["Public"] = "public"; + ShareGroupType["Private"] = "private"; +})(ShareGroupType || (exports.ShareGroupType = ShareGroupType = {})); +var EntityType; +(function (EntityType) { + EntityType["PointCloud"] = "clouds"; + EntityType["Image"] = "images"; + EntityType["BIM"] = "bim"; + EntityType["Unknown"] = "unknown"; +})(EntityType || (exports.EntityType = EntityType = {})); diff --git a/build/organizations/services/OrganizationService.d.ts b/build/organizations/services/OrganizationService.d.ts new file mode 100644 index 0000000..afa244a --- /dev/null +++ b/build/organizations/services/OrganizationService.d.ts @@ -0,0 +1,39 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IOrganizationDb } from '../../interfaces'; +export declare class OrganizationService { + protected model: import("mongoose").Model & IOrganizationDb & Required<{ + _id: string; + }>, any>; + protected configure(): void; + insert(organization: IOrganizationDb): Promise; + get(organization_id: string): Promise; + getPopulated(organization_id: string): Promise; + update(organization: IOrganizationDb): Promise; + remove(organization_id: string): Promise; + exists(organization_id: string): Promise; + listAllFromUser(user_id: string): Promise>; +} diff --git a/build/organizations/services/OrganizationService.js b/build/organizations/services/OrganizationService.js new file mode 100644 index 0000000..daa61a6 --- /dev/null +++ b/build/organizations/services/OrganizationService.js @@ -0,0 +1,118 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.OrganizationService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const connection_1 = require("../../connection"); +const validationOrgModel_1 = require("../validationOrgModel"); +const validationUserModel_1 = require("../../users/validationUserModel"); +class OrganizationService { + constructor() { + this.model = validationOrgModel_1.organizationModel; + } + configure() { } + insert(organization) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organization_record = new this.model(organization); + yield organization_record.save(); + return organization_record.toJSON(); + }); + } + get(organization_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organization_record = yield this.model + .findById(organization_id) + .lean() + .exec(); + if (!organization_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; + err.Details = `Organization '${organization_id}' not found'`; + throw err; + } + return organization_record; + }); + } + getPopulated(organization_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organization_record = yield this.model + .findById(organization_id) + .populate({ + path: 'members.user', + model: validationUserModel_1.UserModel, + select: '_id name lastName email', + }) + .lean() + .exec(); + if (!organization_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; + err.Details = `Organization '${organization_id}' not found'`; + throw err; + } + return organization_record; + }); + } + update(organization) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organization_record = yield this.model.findByIdAndUpdate(organization._id, organization, { + new: true, + }); + if (!organization_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; + err.Details = `Organization '${organization._id}' not found'`; + throw err; + } + return organization_record.toJSON(); + }); + } + remove(organization_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = yield this.exists(organization_id); + if (!exists) { + const err = duna_web_platform_error_defs_1.ErrorMessages.OrganizationDoesNotExist; + err.Details = `Organization '${organization_id}' not found'`; + throw err; + } + yield this.model.findByIdAndRemove(organization_id); + }); + } + exists(organization_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = (yield this.model.exists({ _id: organization_id }).lean().exec()) != + null; + return exists; + }); + } + listAllFromUser(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const organizations = yield this.model + .find({ 'members.user': user_id }) + .select('_id name members') + .lean() + .exec(); + return organizations; + }); + } +} +exports.OrganizationService = OrganizationService; diff --git a/build/organizations/validationOrgDb.d.ts b/build/organizations/validationOrgDb.d.ts new file mode 100644 index 0000000..3904440 --- /dev/null +++ b/build/organizations/validationOrgDb.d.ts @@ -0,0 +1 @@ +export declare function createOrganizationCollectionWithValidation(uri: string, databaseName: string, collection_organizations: string): Promise; diff --git a/build/organizations/validationOrgDb.js b/build/organizations/validationOrgDb.js new file mode 100644 index 0000000..09b565b --- /dev/null +++ b/build/organizations/validationOrgDb.js @@ -0,0 +1,82 @@ +"use strict"; +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.createOrganizationCollectionWithValidation = void 0; +const dotenv_1 = __importDefault(require("dotenv")); +const mongodb_1 = require("mongodb"); +dotenv_1.default.config(); +function createOrganizationCollectionWithValidation(uri, databaseName, collection_organizations) { + return __awaiter(this, void 0, void 0, function* () { + const client = new mongodb_1.MongoClient(uri); + yield client.connect(); + const db = client.db(databaseName); + const colecao = db.collection(collection_organizations); + const validationRules = { + validator: { + $jsonSchema: { + bsonType: 'object', + required: ['_id', 'memberLimit', 'name', 'type', 'members'], + properties: { + _id: { + bsonType: 'string', + description: '_id must be a string and is required.', + }, + memberLimit: { + bsonType: 'number', + description: 'memberLimit must be a number and is required.', + }, + name: { + bsonType: 'string', + description: 'name must be a string and is required.', + }, + type: { + bsonType: 'string', + description: 'type must be a string and is required.', + }, + members: { + bsonType: 'array', + description: 'members must be an array and is required.', + items: { + bsonType: 'object', + required: ['user', 'role'], + properties: { + user: { + bsonType: 'string', + description: 'user must be a string and is required.', + }, + role: { + bsonType: 'string', + description: 'role must be a string and is required.', + }, + }, + }, + }, + }, + }, + }, + validationLevel: 'strict', + validationAction: 'error', + }; + yield colecao.createIndex({ user: 1 }); + yield db.command({ + collMod: collection_organizations, + validator: validationRules.validator, + validationLevel: validationRules.validationLevel, + validationAction: validationRules.validationAction, + }); + console.log(`Collection ${collection_organizations} with validation rules created successfully.`); + yield client.close(); + }); +} +exports.createOrganizationCollectionWithValidation = createOrganizationCollectionWithValidation; diff --git a/build/organizations/validationOrgModel.d.ts b/build/organizations/validationOrgModel.d.ts new file mode 100644 index 0000000..3904cf6 --- /dev/null +++ b/build/organizations/validationOrgModel.d.ts @@ -0,0 +1,29 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IOrganizationDb } from '../interfaces'; +export declare const organizationModel: import("mongoose").Model & IOrganizationDb & Required<{ + _id: string; +}>, any>; diff --git a/build/organizations/validationOrgModel.js b/build/organizations/validationOrgModel.js new file mode 100644 index 0000000..f89227c --- /dev/null +++ b/build/organizations/validationOrgModel.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.organizationModel = void 0; +const mongoose_1 = require("mongoose"); +const organizationSchema = new mongoose_1.Schema({ + _id: { type: String, required: true }, + memberLimit: { type: Number, required: true }, + name: { type: String, required: true }, + type: { type: String, required: true }, + members: [ + { + _id: false, + user: { type: String, required: true, index: true }, + role: { type: String, required: true }, + }, + ], +}); +exports.organizationModel = (0, mongoose_1.model)('organization', organizationSchema); diff --git a/build/projects/services/ProjectService.d.ts b/build/projects/services/ProjectService.d.ts new file mode 100644 index 0000000..64fd378 --- /dev/null +++ b/build/projects/services/ProjectService.d.ts @@ -0,0 +1,43 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IProjectDb } from '../../interfaces'; +export declare class ProjectService { + protected model: import("mongoose").Model & IProjectDb & Required<{ + _id: string; + }>, any>; + protected configure(): void; + insert(project: IProjectDb): Promise; + get(project_id: string, user_id: string): Promise; + getPopulated(project_id: string, user_id: string): Promise; + update(project: IProjectDb): Promise; + remove(project_id: string, user_id: string): Promise; + removeAllFromUser(user_id: string): Promise; + exists(project_id: string, user_id: string): Promise; + existsWithName(user_id: string, project_name: string): Promise; + listAllFromUser(user_id: string): Promise; + listAllFromUserPopulated(user_id: string): Promise; + listAll(): Promise; +} diff --git a/build/projects/services/ProjectService.js b/build/projects/services/ProjectService.js new file mode 100644 index 0000000..1616183 --- /dev/null +++ b/build/projects/services/ProjectService.js @@ -0,0 +1,156 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ProjectService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const validationProjectsModel_1 = require("../validationProjectsModel"); +const connection_1 = require("../../connection"); +class ProjectService { + constructor() { + this.model = validationProjectsModel_1.projectModel; + } + configure() { } + insert(project) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project_record = new this.model(project); + yield project_record.save(); + return project_record.toJSON(); + }); + } + get(project_id, user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project_record = yield this.model + .findOne({ _id: project_id, user_id: user_id }) + .lean() + .exec(); + if (!project_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; + err.Details = `Project '${project_id}' not found'`; + throw err; + } + return project_record; + }); + } + getPopulated(project_id, user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project_record = yield this.model + .findOne({ _id: project_id, user_id: user_id }) + .populate('clouds') + .populate('bim') + .populate('images') + .lean() + .exec(); + if (!project_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; + err.Details = `Project '${project_id}' not found'`; + throw err; + } + return project_record; + }); + } + update(project) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project_record = yield this.model.findByIdAndUpdate(project._id, project, { + new: true, + }); + if (!project_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; + err.Details = `Project '${project._id}' not found'`; + throw err; + } + return project_record.toJSON(); + }); + } + remove(project_id, user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = yield this.exists(project_id, user_id); + if (!exists) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ProjectDoesNotExist; + err.Details = `Project '${project_id}' not found'`; + throw err; + } + yield this.model.findByIdAndRemove(project_id); + }); + } + removeAllFromUser(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + yield this.model.deleteMany({ user_id: user_id }); + }); + } + exists(project_id, user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const exists = (yield this.model + .exists({ _id: project_id, user_id: user_id }) + .lean() + .exec()) != null; + return exists; + }); + } + existsWithName(user_id, project_name) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const project = yield this.model + .findOne({ user_id: user_id, name: project_name }) + .lean() + .exec(); + return project != null; + }); + } + listAllFromUser(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const projects = yield this.model + .find({ user_id: user_id }) + .lean() + .exec(); + return projects; + }); + } + listAllFromUserPopulated(user_id) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const projects = yield this.model + .find({ user_id: user_id }) + .populate('clouds') + .populate('bim') + .populate('images') + .lean() + .exec(); + return projects; + }); + } + listAll() { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const projects = yield this.model.find().lean().exec(); + return projects; + }); + } +} +exports.ProjectService = ProjectService; diff --git a/build/projects/validationProjectsDb.d.ts b/build/projects/validationProjectsDb.d.ts new file mode 100644 index 0000000..036c18b --- /dev/null +++ b/build/projects/validationProjectsDb.d.ts @@ -0,0 +1 @@ +export declare function createProjectCollectionWithValidation(uri: string, databaseName: string, collection_projects: string): Promise; diff --git a/build/projects/validationProjectsDb.js b/build/projects/validationProjectsDb.js new file mode 100644 index 0000000..f44a3f7 --- /dev/null +++ b/build/projects/validationProjectsDb.js @@ -0,0 +1,140 @@ +"use strict"; +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.createProjectCollectionWithValidation = void 0; +const dotenv_1 = __importDefault(require("dotenv")); +const mongodb_1 = require("mongodb"); +dotenv_1.default.config(); +function createProjectCollectionWithValidation(uri, databaseName, collection_projects) { + return __awaiter(this, void 0, void 0, function* () { + const client = new mongodb_1.MongoClient(uri); + yield client.connect(); + const db = client.db(databaseName); + const colecao = db.collection(collection_projects); + const validationRules = { + validator: { + $jsonSchema: { + bsonType: 'object', + required: [ + '_id', + 'user_id', + 'name', + 'clientName', + 'type', + 'favorite', + 'clouds', + 'images', + 'bim', + 'projectQuota', + 'createdAt', + 'modifiedAt', + 'publicAccessToken', + 'status', + ], + properties: { + _id: { + bsonType: 'string', + description: 'ID do projeto (string)', + }, + user_id: { + bsonType: 'string', + description: 'ID do usuário (string)', + }, + name: { + bsonType: 'string', + description: 'Nome do projeto (string)', + }, + clientName: { + bsonType: 'string', + description: 'Nome do cliente (string)', + }, + type: { + bsonType: 'string', + description: 'Tipo do projeto (string)', + }, + favorite: { + bsonType: 'bool', + description: 'Indicador de favorito (boolean)', + }, + clouds: { + bsonType: 'array', + items: { bsonType: 'string' }, + description: 'Lista de nuvens associadas (array de strings)', + }, + images: { + bsonType: 'array', + items: { bsonType: 'string' }, + description: 'Lista de imagens associadas (array de strings)', + }, + bim: { + bsonType: 'array', + items: { bsonType: 'string' }, + description: 'Lista de modelos BIM associados (array de strings)', + }, + projectQuota: { + bsonType: 'object', + required: [ + 'pointCloudUsedMB', + 'imageUsedMB', + 'BIMUsedMB', + ], + properties: { + pointCloudUsedMB: { + bsonType: 'number', + description: 'Uso de nuvem de pontos (number)', + }, + imageUsedMB: { + bsonType: 'number', + description: 'Uso de tamanho da imagem (number)', + }, + BIMUsedMB: { + bsonType: 'number', + description: 'Uso de tamanho do BIM (number)', + }, + }, + }, + createdAt: { + bsonType: 'number', + description: 'Timestamp de criação (number)', + }, + modifiedAt: { + bsonType: 'number', + description: 'Timestamp de modificação (number)', + }, + publicAccessToken: { + bsonType: 'string', + description: 'Token de acesso público (string)', + }, + status: { + bsonType: 'string', + description: 'Status do projeto (string)', + }, + }, + }, + }, + validationLevel: 'strict', + validationAction: 'error', + }; + yield colecao.createIndex({ user_id: 1 }); + yield db.command({ + collMod: collection_projects, + validator: validationRules.validator, + validationLevel: validationRules.validationLevel, + validationAction: validationRules.validationAction, + }); + console.log(`Collection ${collection_projects} with validation rules created successfully.`); + yield client.close(); + }); +} +exports.createProjectCollectionWithValidation = createProjectCollectionWithValidation; diff --git a/build/projects/validationProjectsModel.d.ts b/build/projects/validationProjectsModel.d.ts new file mode 100644 index 0000000..e24a0ec --- /dev/null +++ b/build/projects/validationProjectsModel.d.ts @@ -0,0 +1,29 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IProjectDb } from '../interfaces'; +export declare const projectModel: import("mongoose").Model & IProjectDb & Required<{ + _id: string; +}>, any>; diff --git a/build/projects/validationProjectsModel.js b/build/projects/validationProjectsModel.js new file mode 100644 index 0000000..bbfe911 --- /dev/null +++ b/build/projects/validationProjectsModel.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.projectModel = void 0; +const mongoose_1 = require("mongoose"); +const projectSchema = new mongoose_1.Schema({ + _id: { type: String, required: true }, + user_id: { type: String, required: true, index: true }, + name: { type: String, required: true }, + clientName: { type: String, required: true }, + type: { type: String, required: true }, + snapshot: { type: String, required: false }, + favorite: { type: Boolean, required: true }, + clouds: { type: [String], default: [], ref: 'entity' }, + images: { type: [String], default: [], ref: 'entity' }, + bim: { type: [String], default: [], ref: 'entity' }, + projectQuota: { + pointCloudUsedMB: { type: Number, required: true }, + imageUsedMB: { type: Number, required: true }, + BIMUsedMB: { type: Number, required: true }, + }, + createdAt: { type: Number, required: true }, + modifiedAt: { type: Number, required: true }, + owner: { type: String, required: false }, + accessType: { type: String, required: false }, + publicAccessToken: { type: String, required: true }, + status: { type: String, required: true }, +}); +exports.projectModel = (0, mongoose_1.model)('project', projectSchema); diff --git a/build/users/services/createUserService.d.ts b/build/users/services/createUserService.d.ts new file mode 100644 index 0000000..717b62f --- /dev/null +++ b/build/users/services/createUserService.d.ts @@ -0,0 +1,2 @@ +import { IUsers } from '../../interfaces'; +export declare function createUserService(user: IUsers): Promise; diff --git a/build/users/services/createUserService.js b/build/users/services/createUserService.js new file mode 100644 index 0000000..90d9545 --- /dev/null +++ b/build/users/services/createUserService.js @@ -0,0 +1,64 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createUserService = void 0; +const validationUserModel_1 = require("../validationUserModel"); +const uuid_1 = require("uuid"); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function createUserService(user) { + return __awaiter(this, void 0, void 0, function* () { + try { + const existingUser = yield validationUserModel_1.UserModel.findOne({ email: user.email }); + if (existingUser) { + const err = duna_web_platform_error_defs_1.ErrorMessages.ResourceExists; + throw err; + } + const newUser = new validationUserModel_1.UserModel({ + _id: (0, uuid_1.v4)(), + name: user.name, + lastName: user.lastName, + email: user.email, + password: user.password, + actingField: user.actingField, + phoneNumber: user.phoneNumber, + postalCode: user.postalCode, + useObjective: user.useObjective, + imagePath: user.imagePath, + street: user.street, + number: user.number, + complement: user.complement, + quota: { + BIMSizeQuotaMB: 5000, + pointCloudQuotaMB: 5000, + imageSizeQuotaMB: 5000, + BIMUsedMB: 0, + imageUsedMB: 0, + pointCloudUsedMB: 0, + }, + paymentInfo: { + customerId: user.paymentInfo.customerId, + plan: user.paymentInfo.plan, + expirationDate: user.paymentInfo.expirationDate, + }, + }); + const savedUser = yield newUser.save(); + return savedUser; + } + catch (error) { + if (error !== duna_web_platform_error_defs_1.ErrorMessages.ResourceExists) { + error = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + error.Details = 'Possibly wrong data schema.'; + } + throw error; + } + }); +} +exports.createUserService = createUserService; diff --git a/build/users/services/deleteUserService.d.ts b/build/users/services/deleteUserService.d.ts new file mode 100644 index 0000000..83f05a5 --- /dev/null +++ b/build/users/services/deleteUserService.d.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +export declare function deleteUserService(userId: string): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ + _id: string; +}>) | null>; diff --git a/build/users/services/deleteUserService.js b/build/users/services/deleteUserService.js new file mode 100644 index 0000000..097dd49 --- /dev/null +++ b/build/users/services/deleteUserService.js @@ -0,0 +1,27 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteUserService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const validationUserModel_1 = require("../validationUserModel"); +function deleteUserService(userId) { + return __awaiter(this, void 0, void 0, function* () { + try { + return yield validationUserModel_1.UserModel.findOneAndDelete({ _id: userId }); + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Internal server Error '; + throw err; + } + }); +} +exports.deleteUserService = deleteUserService; diff --git a/build/users/services/getOneUserService.d.ts b/build/users/services/getOneUserService.d.ts new file mode 100644 index 0000000..8f7d2e7 --- /dev/null +++ b/build/users/services/getOneUserService.d.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +export declare function getOneUserService(_id: string): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ + _id: string; +}>) | null>; diff --git a/build/users/services/getOneUserService.js b/build/users/services/getOneUserService.js new file mode 100644 index 0000000..88556cc --- /dev/null +++ b/build/users/services/getOneUserService.js @@ -0,0 +1,28 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getOneUserService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const validationUserModel_1 = require("../validationUserModel"); +function getOneUserService(_id) { + return __awaiter(this, void 0, void 0, function* () { + try { + const user = yield validationUserModel_1.UserModel.findOne({ _id }); + return user; + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Internal server Error '; + throw err; + } + }); +} +exports.getOneUserService = getOneUserService; diff --git a/build/users/services/getUsersService.d.ts b/build/users/services/getUsersService.d.ts new file mode 100644 index 0000000..9602c32 --- /dev/null +++ b/build/users/services/getUsersService.d.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +export declare function getUsersService(): Promise<(import("mongoose").Document & import("../..").IUsers & Required<{ + _id: string; +}>)[]>; diff --git a/build/users/services/getUsersService.js b/build/users/services/getUsersService.js new file mode 100644 index 0000000..fada50f --- /dev/null +++ b/build/users/services/getUsersService.js @@ -0,0 +1,28 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getUsersService = void 0; +const validationUserModel_1 = require("../validationUserModel"); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function getUsersService() { + return __awaiter(this, void 0, void 0, function* () { + try { + const user = yield validationUserModel_1.UserModel.find(); + return user; + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Internal server Error '; + throw err; + } + }); +} +exports.getUsersService = getUsersService; diff --git a/build/users/services/loginService.d.ts b/build/users/services/loginService.d.ts new file mode 100644 index 0000000..f30fbd0 --- /dev/null +++ b/build/users/services/loginService.d.ts @@ -0,0 +1,2 @@ +import { IUsers } from '../../interfaces'; +export declare function getUserByEmail(email: string): Promise; diff --git a/build/users/services/loginService.js b/build/users/services/loginService.js new file mode 100644 index 0000000..b90a214 --- /dev/null +++ b/build/users/services/loginService.js @@ -0,0 +1,28 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getUserByEmail = void 0; +const validationUserModel_1 = require("../validationUserModel"); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function getUserByEmail(email) { + return __awaiter(this, void 0, void 0, function* () { + try { + const user = yield validationUserModel_1.UserModel.findOne({ email }).exec(); + return user; + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Internal server Error '; + throw err; + } + }); +} +exports.getUserByEmail = getUserByEmail; diff --git a/build/users/services/updateCustomerIdService.d.ts b/build/users/services/updateCustomerIdService.d.ts new file mode 100644 index 0000000..26e7ef8 --- /dev/null +++ b/build/users/services/updateCustomerIdService.d.ts @@ -0,0 +1,2 @@ +import { IUsers } from '../../interfaces'; +export declare function updateCustomerId(email: string, updates: Partial): Promise; diff --git a/build/users/services/updateCustomerIdService.js b/build/users/services/updateCustomerIdService.js new file mode 100644 index 0000000..b1ac949 --- /dev/null +++ b/build/users/services/updateCustomerIdService.js @@ -0,0 +1,42 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateCustomerId = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const validationUserModel_1 = require("../validationUserModel"); +function updateCustomerId(email, updates) { + return __awaiter(this, void 0, void 0, function* () { + try { + const filter = { email }; + const update = { + $set: { + 'paymentInfo.customerId': updates.customerId, + 'paymentInfo.plan': updates.plan, + 'paymentInfo.expirationDate': updates.expirationDate, + }, + }; + const options = { new: true }; + const updatedUser = yield validationUserModel_1.UserModel.findOneAndUpdate(filter, update, options); + if (!updatedUser) { + const err = duna_web_platform_error_defs_1.ErrorMessages.UserNotFound.Message; + throw err; + } + return updatedUser; + } + catch (error) { + console.error('Error in updateCustomerId:', error); + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Error updating user data.'; + throw err; + } + }); +} +exports.updateCustomerId = updateCustomerId; diff --git a/build/users/services/updateUserService.d.ts b/build/users/services/updateUserService.d.ts new file mode 100644 index 0000000..cc3e1e3 --- /dev/null +++ b/build/users/services/updateUserService.d.ts @@ -0,0 +1,2 @@ +import { IUsers } from '../../interfaces'; +export declare function updateUserService(userId: string, updates: Partial): Promise; diff --git a/build/users/services/updateUserService.js b/build/users/services/updateUserService.js new file mode 100644 index 0000000..b284704 --- /dev/null +++ b/build/users/services/updateUserService.js @@ -0,0 +1,58 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateUserService = void 0; +const validationUserModel_1 = require("../validationUserModel"); +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +function updateUserService(userId, updates) { + return __awaiter(this, void 0, void 0, function* () { + try { + const existingUser = yield validationUserModel_1.UserModel.findById(userId); + if (!existingUser) { + return null; + } + if (updates.name) + existingUser.name = updates.name; + if (updates.lastName) + existingUser.lastName = updates.lastName; + if (updates.email) + existingUser.email = updates.email; + if (updates.password) + existingUser.password = updates.password; + if (updates.actingField) + existingUser.actingField = updates.actingField; + if (updates.phoneNumber) + existingUser.phoneNumber = updates.phoneNumber; + if (updates.postalCode) + existingUser.postalCode = updates.postalCode; + if (updates.useObjective) + existingUser.useObjective = updates.useObjective; + if (updates.imagePath) + existingUser.imagePath = updates.imagePath; + if (updates.street) + existingUser.street = updates.street; + if (updates.number) + existingUser.number = updates.number; + if (updates.complement) + existingUser.complement = updates.complement; + if (updates.quota) + existingUser.quota = updates.quota; + yield existingUser.save(); + return existingUser; + } + catch (error) { + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = 'Error updating user data.'; + throw err; + } + }); +} +exports.updateUserService = updateUserService; diff --git a/build/users/validationDbUsers.d.ts b/build/users/validationDbUsers.d.ts new file mode 100644 index 0000000..a5d5f32 --- /dev/null +++ b/build/users/validationDbUsers.d.ts @@ -0,0 +1 @@ +export declare function createUserCollectionWithValidation(uri: string, databaseName: string, collectionName: string): Promise; diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js new file mode 100644 index 0000000..fe39caf --- /dev/null +++ b/build/users/validationDbUsers.js @@ -0,0 +1,121 @@ +"use strict"; +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.createUserCollectionWithValidation = void 0; +const dotenv_1 = __importDefault(require("dotenv")); +const mongodb_1 = require("mongodb"); +dotenv_1.default.config(); +function createUserCollectionWithValidation(uri, databaseName, collectionName) { + return __awaiter(this, void 0, void 0, function* () { + const client = new mongodb_1.MongoClient(uri); + yield client.connect(); + const db = client.db(databaseName); + const colecao = db.collection(collectionName); + const validationRules = { + validator: { + $jsonSchema: { + bsonType: 'object', + required: [ + 'name', + 'lastName', + 'password', + 'postalCode', + 'street', + 'number', + 'quota', + ], + properties: { + name: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + lastName: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + password: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + postalCode: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + street: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + number: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + complement: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + quota: { + bsonType: 'object', + required: [ + 'pointCloudQuotaMB', + 'imageSizeQuotaMB', + 'BIMSizeQuotaMB', + 'pointCloudUsedMB', + 'imageUsedMB', + 'BIMUsedMB', + ], + properties: { + pointCloudQuotaMB: { + bsonType: 'number', + description: 'Quota para nuvem de pontos (number)', + }, + imageSizeQuotaMB: { + bsonType: 'number', + description: 'Quota para tamanho da imagem (number)', + }, + BIMSizeQuotaMB: { + bsonType: 'number', + description: 'Quota para tamanho do BIM (number)', + }, + pointCloudUsedMB: { + bsonType: 'number', + description: 'Uso de nuvem de pontos (number)', + }, + imageUsedMB: { + bsonType: 'number', + description: 'Uso de tamanho da imagem (number)', + }, + BIMUsedMB: { + bsonType: 'number', + description: 'Uso de tamanho do BIM (number)', + }, + }, + }, + }, + }, + }, + validationLevel: 'strict', + validationAction: 'error', + }; + yield colecao.createIndex({ _id: 1 }); + yield db.command({ + collMod: colecao.collectionName, + validator: validationRules.validator, + validationLevel: validationRules.validationLevel, + validationAction: validationRules.validationAction, + }); + console.log(`Coleção ${collectionName} com regras de validação criada com sucesso.`); + yield client.close(); + }); +} +exports.createUserCollectionWithValidation = createUserCollectionWithValidation; diff --git a/build/users/validationUserModel.d.ts b/build/users/validationUserModel.d.ts new file mode 100644 index 0000000..86c6c19 --- /dev/null +++ b/build/users/validationUserModel.d.ts @@ -0,0 +1,4 @@ +import { Model } from 'mongoose'; +import { IUsers } from '../interfaces'; +declare const UserModel: Model; +export { UserModel }; diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js new file mode 100644 index 0000000..76ac5dd --- /dev/null +++ b/build/users/validationUserModel.js @@ -0,0 +1,39 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UserModel = void 0; +const mongoose_1 = __importDefault(require("mongoose")); +const UserSchema = new mongoose_1.default.Schema({ + _id: { type: String, required: true }, + name: { type: String, required: true }, + lastName: { type: String, required: true }, + email: { type: String, unique: true }, + password: { type: String, required: true }, + actingField: { type: String, default: '' }, + phoneNumber: { type: String, default: '' }, + postalCode: { type: String, required: true, default: '' }, + useObjective: { type: String, default: '' }, + imagePath: { type: String, default: '' }, + street: { type: String, required: true, default: '' }, + number: { type: String, required: true, default: '' }, + complement: { type: String, default: '' }, + quota: { + pointCloudQuotaMB: { type: Number, required: true }, + imageSizeQuotaMB: { type: Number, required: true }, + BIMSizeQuotaMB: { type: Number, required: true }, + pointCloudUsedMB: { type: Number, required: true }, + imageUsedMB: { type: Number, required: true }, + BIMUsedMB: { type: Number, required: true }, + }, + paymentInfo: { + customerId: { type: String, required: false, default: '' }, + plan: { type: String, required: false, default: '' }, + expirationDate: { type: String, required: false, default: '' }, + }, + customerId: { type: String, required: false }, + validatedMail: { type: Boolean, required: true, default: false }, +}); +const UserModel = mongoose_1.default.model('user', UserSchema); +exports.UserModel = UserModel; diff --git a/build/usersProject/UserService.d.ts b/build/usersProject/UserService.d.ts new file mode 100644 index 0000000..3774e0f --- /dev/null +++ b/build/usersProject/UserService.d.ts @@ -0,0 +1,34 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +import { IUsers } from '../interfaces'; +export declare class UserService { + protected model: import("mongoose").Model & IUsers & Required<{ + _id: string; + }>, any>; + protected configure(): void; + get(user_id?: string, email?: string): Promise; + update(user: IUsers): Promise; +} diff --git a/build/usersProject/UserService.js b/build/usersProject/UserService.js new file mode 100644 index 0000000..ec1a453 --- /dev/null +++ b/build/usersProject/UserService.js @@ -0,0 +1,57 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UserService = void 0; +const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); +const connection_1 = require("../connection"); +const validationUserModel_1 = require("../users/validationUserModel"); +class UserService { + constructor() { + this.model = validationUserModel_1.UserModel; + } + configure() { } + get(user_id, email) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + let user; + if (user_id) { + user = yield this.model.findById(user_id).lean().exec(); + } + else { + user = yield this.model.findOne({ email: email }).lean().exec(); + } + if (!user) { + const id = user_id ? user_id : email; + const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; + err.Details = `User ${id} not found`; + throw err; + } + return user; + }); + } + update(user) { + return __awaiter(this, void 0, void 0, function* () { + //Check if mongoDB is connected + (0, connection_1.checkConnectionStatus)(); + const user_record = yield this.model.findByIdAndUpdate(user._id, user, { + new: true, + }); + if (!user_record) { + const err = duna_web_platform_error_defs_1.ErrorMessages.UserNotFound; + err.Details = `User '${user._id}' not found'`; + throw err; + } + return user_record.toJSON(); + }); + } +} +exports.UserService = UserService; From 20e2ef0fd29b172c92eb05146bfa2327d960ef2a Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 20:28:56 -0300 Subject: [PATCH 13/20] format --- src/users/services/createUserService.ts | 6 +- src/users/services/updateCustomerIdService.ts | 56 ++++++++++--------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/users/services/createUserService.ts b/src/users/services/createUserService.ts index bd0148c..6a38483 100644 --- a/src/users/services/createUserService.ts +++ b/src/users/services/createUserService.ts @@ -35,9 +35,9 @@ export async function createUserService(user: IUsers): Promise { pointCloudUsedMB: 0, }, paymentInfo: { - customerId: user.paymentInfo.customerId , - plan: user.paymentInfo.plan , - expirationDate: user.paymentInfo.expirationDate , + customerId: user.paymentInfo.customerId, + plan: user.paymentInfo.plan, + expirationDate: user.paymentInfo.expirationDate, }, }) diff --git a/src/users/services/updateCustomerIdService.ts b/src/users/services/updateCustomerIdService.ts index a09f147..25ce740 100644 --- a/src/users/services/updateCustomerIdService.ts +++ b/src/users/services/updateCustomerIdService.ts @@ -2,36 +2,38 @@ import { ErrorMessages } from 'duna-web-platform-error-defs' import { IUsers } from '../../interfaces' import { UserModel } from '../validationUserModel' - export async function updateCustomerId( email: string, updates: Partial - ): Promise { +): Promise { try { - const filter = { email }; - const update = { - $set: { - 'paymentInfo.customerId': updates.customerId, - 'paymentInfo.plan': updates.plan, - 'paymentInfo.expirationDate': updates.expirationDate, - }, - }; - - const options = { new: true }; - - const updatedUser = await UserModel.findOneAndUpdate(filter, update, options); - - if (!updatedUser) { - const err = ErrorMessages.UserNotFound.Message - throw err; - } - - return updatedUser; + const filter = { email } + const update = { + $set: { + 'paymentInfo.customerId': updates.customerId, + 'paymentInfo.plan': updates.plan, + 'paymentInfo.expirationDate': updates.expirationDate, + }, + } + + const options = { new: true } + + const updatedUser = await UserModel.findOneAndUpdate( + filter, + update, + options + ) + + if (!updatedUser) { + const err = ErrorMessages.UserNotFound.Message + throw err + } + + return updatedUser } catch (error) { - console.error('Error in updateCustomerId:', error); - const err = ErrorMessages.InternalServerError; - err.Details = 'Error updating user data.'; - throw err; + console.error('Error in updateCustomerId:', error) + const err = ErrorMessages.InternalServerError + err.Details = 'Error updating user data.' + throw err } - } - \ No newline at end of file +} From 966ff0f0a4ccc30794b657b4bf4d3e1500208c9b Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 21:03:48 -0300 Subject: [PATCH 14/20] fix: validationDb --- build/users/validationDbUsers.js | 19 +++++++++++++++++++ build/users/validationUserModel.js | 6 +++--- src/users/validationDbUsers.ts | 22 ++++++++++++++++++++++ src/users/validationUserModel.ts | 6 +++--- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js index fe39caf..4f44ec9 100644 --- a/build/users/validationDbUsers.js +++ b/build/users/validationDbUsers.js @@ -34,6 +34,7 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { 'street', 'number', 'quota', + 'paymentInfo', ], properties: { name: { @@ -101,6 +102,24 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { }, }, }, + paymentInfo: { + bsonType: 'object', + required: ['customerId', 'plan', 'expirationDate'], + properties: { + customerId: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + plan: { + bsonType: 'string', + description: 'Deve ser uma string e é obrigatório.', + }, + expirationDate: { + bsonType: 'date', + description: 'Deve ser uma data e é obrigatório.', + }, + }, + }, }, }, }, diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js index 76ac5dd..b585e2d 100644 --- a/build/users/validationUserModel.js +++ b/build/users/validationUserModel.js @@ -28,9 +28,9 @@ const UserSchema = new mongoose_1.default.Schema({ BIMUsedMB: { type: Number, required: true }, }, paymentInfo: { - customerId: { type: String, required: false, default: '' }, - plan: { type: String, required: false, default: '' }, - expirationDate: { type: String, required: false, default: '' }, + customerId: { type: String, required: true, default: '' }, + plan: { type: String, required: true, default: '' }, + expirationDate: { type: String, required: true, default: '' }, }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, diff --git a/src/users/validationDbUsers.ts b/src/users/validationDbUsers.ts index bde3198..5c7c000 100644 --- a/src/users/validationDbUsers.ts +++ b/src/users/validationDbUsers.ts @@ -26,6 +26,7 @@ export async function createUserCollectionWithValidation( 'street', 'number', 'quota', + 'paymentInfo', ], properties: { name: { @@ -97,6 +98,27 @@ export async function createUserCollectionWithValidation( }, }, }, + paymentInfo: { + bsonType: 'object', + required: ['customerId', 'plan', 'expirationDate'], + properties: { + customerId: { + bsonType: 'string', + description: + 'Deve ser uma string e é obrigatório.', + }, + plan: { + bsonType: 'string', + description: + 'Deve ser uma string e é obrigatório.', + }, + expirationDate: { + bsonType: 'date', + description: + 'Deve ser uma data e é obrigatório.', + }, + }, + }, }, }, }, diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index 9a6f753..81870d8 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -24,9 +24,9 @@ const UserSchema = new mongoose.Schema({ BIMUsedMB: { type: Number, required: true }, }, paymentInfo: { - customerId: { type: String, required: false, default: '' }, - plan: { type: String, required: false, default: '' }, - expirationDate: { type: String, required: false, default: '' }, + customerId: { type: String, required: true, default: '' }, + plan: { type: String, required: true, default: '' }, + expirationDate: { type: String, required: true, default: '' }, }, customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, From a3dd6924e47dddab87a9c70b88eb7992337c18d9 Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 21:09:31 -0300 Subject: [PATCH 15/20] fix: validationDb --- build/users/validationUserModel.js | 1 - src/users/validationUserModel.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js index b585e2d..33b1ab2 100644 --- a/build/users/validationUserModel.js +++ b/build/users/validationUserModel.js @@ -32,7 +32,6 @@ const UserSchema = new mongoose_1.default.Schema({ plan: { type: String, required: true, default: '' }, expirationDate: { type: String, required: true, default: '' }, }, - customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, }); const UserModel = mongoose_1.default.model('user', UserSchema); diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index 81870d8..eb70ba4 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -28,7 +28,6 @@ const UserSchema = new mongoose.Schema({ plan: { type: String, required: true, default: '' }, expirationDate: { type: String, required: true, default: '' }, }, - customerId: { type: String, required: false }, validatedMail: { type: Boolean, required: true, default: false }, }) From 127b9425fadc80b36b2abd3dab4a4cc00e56eedf Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 21:11:48 -0300 Subject: [PATCH 16/20] fix:validationDb and model --- build/users/validationDbUsers.js | 19 ------------------- build/users/validationUserModel.js | 6 +++--- src/users/validationDbUsers.ts | 24 ++---------------------- src/users/validationUserModel.ts | 6 +++--- 4 files changed, 8 insertions(+), 47 deletions(-) diff --git a/build/users/validationDbUsers.js b/build/users/validationDbUsers.js index 4f44ec9..fe39caf 100644 --- a/build/users/validationDbUsers.js +++ b/build/users/validationDbUsers.js @@ -34,7 +34,6 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { 'street', 'number', 'quota', - 'paymentInfo', ], properties: { name: { @@ -102,24 +101,6 @@ function createUserCollectionWithValidation(uri, databaseName, collectionName) { }, }, }, - paymentInfo: { - bsonType: 'object', - required: ['customerId', 'plan', 'expirationDate'], - properties: { - customerId: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - plan: { - bsonType: 'string', - description: 'Deve ser uma string e é obrigatório.', - }, - expirationDate: { - bsonType: 'date', - description: 'Deve ser uma data e é obrigatório.', - }, - }, - }, }, }, }, diff --git a/build/users/validationUserModel.js b/build/users/validationUserModel.js index 33b1ab2..09850c1 100644 --- a/build/users/validationUserModel.js +++ b/build/users/validationUserModel.js @@ -28,9 +28,9 @@ const UserSchema = new mongoose_1.default.Schema({ BIMUsedMB: { type: Number, required: true }, }, paymentInfo: { - customerId: { type: String, required: true, default: '' }, - plan: { type: String, required: true, default: '' }, - expirationDate: { type: String, required: true, default: '' }, + customerId: { type: String, required: false, default: '' }, + plan: { type: String, required: false, default: '' }, + expirationDate: { type: String, required: false, default: '' }, }, validatedMail: { type: Boolean, required: true, default: false }, }); diff --git a/src/users/validationDbUsers.ts b/src/users/validationDbUsers.ts index 5c7c000..1a0518f 100644 --- a/src/users/validationDbUsers.ts +++ b/src/users/validationDbUsers.ts @@ -26,7 +26,6 @@ export async function createUserCollectionWithValidation( 'street', 'number', 'quota', - 'paymentInfo', ], properties: { name: { @@ -97,28 +96,9 @@ export async function createUserCollectionWithValidation( description: 'Uso de tamanho do BIM (number)', }, }, + }, - paymentInfo: { - bsonType: 'object', - required: ['customerId', 'plan', 'expirationDate'], - properties: { - customerId: { - bsonType: 'string', - description: - 'Deve ser uma string e é obrigatório.', - }, - plan: { - bsonType: 'string', - description: - 'Deve ser uma string e é obrigatório.', - }, - expirationDate: { - bsonType: 'date', - description: - 'Deve ser uma data e é obrigatório.', - }, - }, - }, + }, }, }, diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index eb70ba4..9d08b4c 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -24,9 +24,9 @@ const UserSchema = new mongoose.Schema({ BIMUsedMB: { type: Number, required: true }, }, paymentInfo: { - customerId: { type: String, required: true, default: '' }, - plan: { type: String, required: true, default: '' }, - expirationDate: { type: String, required: true, default: '' }, + customerId: { type: String, required: false, default: '' }, + plan: { type: String, required: false, default: '' }, + expirationDate: { type: String, required: false, default: '' }, }, validatedMail: { type: Boolean, required: true, default: false }, }) From 70f279c566da1215089859a3b0b0dac5c39bd1df Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Mon, 15 Jan 2024 21:13:03 -0300 Subject: [PATCH 17/20] format --- src/users/validationDbUsers.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/users/validationDbUsers.ts b/src/users/validationDbUsers.ts index 1a0518f..bde3198 100644 --- a/src/users/validationDbUsers.ts +++ b/src/users/validationDbUsers.ts @@ -96,9 +96,7 @@ export async function createUserCollectionWithValidation( description: 'Uso de tamanho do BIM (number)', }, }, - }, - }, }, }, From 49dbf0eb9657fea7864748c999dc87c25f6ef072 Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Tue, 16 Jan 2024 15:51:44 -0300 Subject: [PATCH 18/20] fix: updatee --- build/users/services/updateUserService.js | 9 +++++++++ src/users/services/updateUserService.ts | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/build/users/services/updateUserService.js b/build/users/services/updateUserService.js index b284704..b753579 100644 --- a/build/users/services/updateUserService.js +++ b/build/users/services/updateUserService.js @@ -45,6 +45,15 @@ function updateUserService(userId, updates) { existingUser.complement = updates.complement; if (updates.quota) existingUser.quota = updates.quota; + if (updates.paymentInfo) { + if (updates.paymentInfo.plan) { + existingUser.paymentInfo.plan = updates.paymentInfo.plan; + } + if (updates.paymentInfo.expirationDate) { + existingUser.paymentInfo.expirationDate = + updates.paymentInfo.expirationDate; + } + } yield existingUser.save(); return existingUser; } diff --git a/src/users/services/updateUserService.ts b/src/users/services/updateUserService.ts index 9319754..26e2553 100644 --- a/src/users/services/updateUserService.ts +++ b/src/users/services/updateUserService.ts @@ -28,6 +28,16 @@ export async function updateUserService( if (updates.complement) existingUser.complement = updates.complement if (updates.quota) existingUser.quota = updates.quota + if (updates.paymentInfo) { + if (updates.paymentInfo.plan) { + existingUser.paymentInfo.plan = updates.paymentInfo.plan + } + if (updates.paymentInfo.expirationDate) { + existingUser.paymentInfo.expirationDate = + updates.paymentInfo.expirationDate + } + } + await existingUser.save() return existingUser From 78fd120103b1ffe08c72de6670a8bbedff144c4b Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Tue, 23 Jan 2024 10:31:33 -0300 Subject: [PATCH 19/20] fix:photogrammetry field --- src/projects/validationProjectsDb.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/projects/validationProjectsDb.ts b/src/projects/validationProjectsDb.ts index 402faee..d2c3560 100644 --- a/src/projects/validationProjectsDb.ts +++ b/src/projects/validationProjectsDb.ts @@ -78,7 +78,7 @@ export async function createProjectCollectionWithValidation( description: 'List of associated BIM entities (string array)', }, - phtogrammetry: { + photogrammetry: { bsonType: 'array', items: { bsonType: 'string' }, description: From 9984e948ef1b61e7504d6fca893111f799739916 Mon Sep 17 00:00:00 2001 From: EliasFernandes03 Date: Tue, 23 Jan 2024 10:32:07 -0300 Subject: [PATCH 20/20] fix:build --- build/projects/validationProjectsDb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/projects/validationProjectsDb.js b/build/projects/validationProjectsDb.js index be6a23b..ccdfbce 100644 --- a/build/projects/validationProjectsDb.js +++ b/build/projects/validationProjectsDb.js @@ -83,7 +83,7 @@ function createProjectCollectionWithValidation(uri, databaseName, collection_pro items: { bsonType: 'string' }, description: 'List of associated BIM entities (string array)', }, - phtogrammetry: { + photogrammetry: { bsonType: 'array', items: { bsonType: 'string' }, description: 'Photogrammetry entity [unique] (string array)',