From d95f2ce7d4464dcb2968479ae6c9a3a12f6b336a Mon Sep 17 00:00:00 2001 From: Behzad-rabiei Date: Sun, 13 Apr 2025 10:32:03 +0200 Subject: [PATCH 1/4] fix: update activated field at update module --- src/services/module.service.ts | 5 +++- src/validations/module.validation.ts | 39 ++++++++++++++-------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/services/module.service.ts b/src/services/module.service.ts index 3f88b29..b7510bb 100644 --- a/src/services/module.service.ts +++ b/src/services/module.service.ts @@ -63,8 +63,11 @@ const updateModule = async ( module: HydratedDocument, updateBody: Partial, ): Promise> => { + console.log(updateBody); if (!updateBody.options?.platforms?.length) { - return module.save(); + Object.assign(module, updateBody); + + return await module.save(); } if (!module.options) { diff --git a/src/validations/module.validation.ts b/src/validations/module.validation.ts index 7896f6f..b7498da 100644 --- a/src/validations/module.validation.ts +++ b/src/validations/module.validation.ts @@ -1,7 +1,10 @@ import Joi from 'joi'; import { - HivemindPlatformNames, ModuleNames, PlatformNames, ViolationDetectionPlatformNames + HivemindPlatformNames, + ModuleNames, + PlatformNames, + ViolationDetectionPlatformNames, } from '@togethercrew.dev/db'; import { objectId } from './custom.validation'; @@ -195,33 +198,31 @@ const dynamicModuleUpdate = (req: any) => { moduleId: Joi.string().custom(objectId).required(), }), }; - let bodyOption = {}; + let bodyOption = { + body: Joi.object().required().keys({ + activated: Joi.boolean(), + }), + }; switch (moduleName) { case ModuleNames.Hivemind: - bodyOption = { - body: Joi.object().required().keys({ - options: hivemindOptions(), - }), - }; + bodyOption.body = bodyOption.body.keys({ + options: hivemindOptions(), + }); break; case ModuleNames.ViolationDetection: - bodyOption = { - body: Joi.object().required().keys({ - options: violationDetectionOptions(), - }), - }; + bodyOption.body = bodyOption.body.keys({ + options: violationDetectionOptions(), + }); break; case ModuleNames.DynamicNft: - bodyOption = { - body: Joi.object().required().keys({ - options: dynamicNftOptions(), - }), - }; + bodyOption.body = bodyOption.body.keys({ + options: dynamicNftOptions(), + }); break; default: - req.allowInput = false; - return {}; + // Allow only activated field update for unknown module types + break; } return { From fce5211a0823a5c39de18607407b385c37612404 Mon Sep 17 00:00:00 2001 From: Behzad-rabiei Date: Sun, 13 Apr 2025 10:37:26 +0200 Subject: [PATCH 2/4] conflict: fix --- src/services/module.service.ts | 11 ++++++----- src/validations/module.validation.ts | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/services/module.service.ts b/src/services/module.service.ts index d671d78..9b3c61a 100644 --- a/src/services/module.service.ts +++ b/src/services/module.service.ts @@ -1,6 +1,6 @@ import { FilterQuery, HydratedDocument, ObjectId, Types } from 'mongoose'; -import { IModule, IModuleUpdateBody, Module } from '@togethercrew.dev/db'; +import { IModule, IModuleUpdateBody, Module, PlatformNames, ModuleNames } from '@togethercrew.dev/db'; import platformService from './platform.service'; import websiteService from './website'; @@ -63,7 +63,6 @@ const updateModule = async ( module: HydratedDocument, updateBody: Partial, ): Promise> => { - console.log(updateBody); if (!updateBody.options?.platforms?.length) { Object.assign(module, updateBody); @@ -92,9 +91,11 @@ const updateModule = async ( const existingPlatform = module.options.platforms.find((p) => p.name === newPlatform.name); if (existingPlatform) { - // if (module.name === ModuleNames.Hivemind && newPlatform.name === PlatformNames.Website) { - // await handleHivemindWebsiteCase(newPlatform); - // } + if (module.name === ModuleNames.Hivemind && newPlatform.name === PlatformNames.Website) { + console.log('A2'); + + await handleHivemindWebsiteCase(newPlatform); + } existingPlatform.metadata = newPlatform.metadata; } else { module.options.platforms.push(newPlatform); diff --git a/src/validations/module.validation.ts b/src/validations/module.validation.ts index 34e011f..9b9b86a 100644 --- a/src/validations/module.validation.ts +++ b/src/validations/module.validation.ts @@ -231,8 +231,8 @@ const dynamicModuleUpdate = (req: any) => { }; break; default: - // Allow only activated field update for unknown module types - break; + req.allowInput = false; + return {}; } return { From c3114379ce2995be5671b13c3b9d7220d29a0ed2 Mon Sep 17 00:00:00 2001 From: Behzad-rabiei Date: Sun, 13 Apr 2025 10:38:20 +0200 Subject: [PATCH 3/4] chore: remove logs and format code --- src/services/module.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/services/module.service.ts b/src/services/module.service.ts index 9b3c61a..2674f87 100644 --- a/src/services/module.service.ts +++ b/src/services/module.service.ts @@ -92,8 +92,6 @@ const updateModule = async ( if (existingPlatform) { if (module.name === ModuleNames.Hivemind && newPlatform.name === PlatformNames.Website) { - console.log('A2'); - await handleHivemindWebsiteCase(newPlatform); } existingPlatform.metadata = newPlatform.metadata; From 925df58595ab0f197082cec8fb29c433efb1425e Mon Sep 17 00:00:00 2001 From: Behzad-rabiei Date: Sun, 13 Apr 2025 10:39:05 +0200 Subject: [PATCH 4/4] chore: remove logs and format code --- src/services/module.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/module.service.ts b/src/services/module.service.ts index 2674f87..151c706 100644 --- a/src/services/module.service.ts +++ b/src/services/module.service.ts @@ -91,9 +91,9 @@ const updateModule = async ( const existingPlatform = module.options.platforms.find((p) => p.name === newPlatform.name); if (existingPlatform) { - if (module.name === ModuleNames.Hivemind && newPlatform.name === PlatformNames.Website) { - await handleHivemindWebsiteCase(newPlatform); - } + // if (module.name === ModuleNames.Hivemind && newPlatform.name === PlatformNames.Website) { + // await handleHivemindWebsiteCase(newPlatform); + // } existingPlatform.metadata = newPlatform.metadata; } else { module.options.platforms.push(newPlatform);