diff --git a/build/index.d.ts b/build/index.d.ts index 71b6d97..c25ed8e 100644 --- a/build/index.d.ts +++ b/build/index.d.ts @@ -21,4 +21,5 @@ 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, }; +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 index 7a8c03c..ac81097 100644 --- a/build/index.js +++ b/build/index.js @@ -1,6 +1,6 @@ "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; +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"); @@ -41,3 +41,5 @@ 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 index e70995e..bd31b77 100644 --- a/build/interfaces.d.ts +++ b/build/interfaces.d.ts @@ -15,6 +15,11 @@ export interface IUsers { complement: string; quota: UserQuota; validatedMail: boolean; + paymentInfo: { + customerId: string; + plan: string; + expirationDate: Date; + }; [key: string]: any; } export interface IEntityDb { 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)', diff --git a/build/users/services/createUserService.js b/build/users/services/createUserService.js index 76903de..ee015ab 100644 --- a/build/users/services/createUserService.js +++ b/build/users/services/createUserService.js @@ -45,6 +45,11 @@ function createUserService(user) { pointCloudUsedMB: 0, photogrammetryUsedMB: 0, }, + 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/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.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/build/users/validationUserModel.js b/build/users/validationUserModel.js index 1f19b82..3b7aae0 100644 --- a/build/users/validationUserModel.js +++ b/build/users/validationUserModel.js @@ -29,6 +29,11 @@ const UserSchema = new mongoose_1.default.Schema({ BIMUsedMB: { type: Number, required: true }, photogrammetryUsedMB: { type: Number, required: true }, }, + paymentInfo: { + 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 }, }); const UserModel = mongoose_1.default.model('user', UserSchema); 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/interfaces.ts b/src/interfaces.ts index 23fb47c..9e0493a 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -15,6 +15,11 @@ export interface IUsers { complement: string quota: UserQuota validatedMail: boolean + paymentInfo: { + customerId: string + plan: string + expirationDate: Date + } [key: string]: any } 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: diff --git a/src/users/services/createUserService.ts b/src/users/services/createUserService.ts index 002633d..57260ec 100644 --- a/src/users/services/createUserService.ts +++ b/src/users/services/createUserService.ts @@ -36,6 +36,11 @@ export async function createUserService(user: IUsers): Promise { pointCloudUsedMB: 0, photogrammetryUsedMB: 0, }, + paymentInfo: { + customerId: user.paymentInfo.customerId, + plan: user.paymentInfo.plan, + expirationDate: user.paymentInfo.expirationDate, + }, }) const savedUser = await newUser.save() diff --git a/src/users/services/updateCustomerIdService.ts b/src/users/services/updateCustomerIdService.ts new file mode 100644 index 0000000..25ce740 --- /dev/null +++ b/src/users/services/updateCustomerIdService.ts @@ -0,0 +1,39 @@ +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 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 + } +} 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 diff --git a/src/users/validationUserModel.ts b/src/users/validationUserModel.ts index ed7e466..d96bbb2 100644 --- a/src/users/validationUserModel.ts +++ b/src/users/validationUserModel.ts @@ -25,6 +25,11 @@ const UserSchema = new mongoose.Schema({ BIMUsedMB: { type: Number, required: true }, photogrammetryUsedMB: { type: Number, required: true }, }, + paymentInfo: { + 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 }, })