Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .migrate
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"lastRun": "1738072787796-update-user-documents-for-telegram-login.ts",
"lastRun": "1738072787797-add-activated-field-to-modules.ts",
"migrations": [
{
"title": "1738072787796-update-user-documents-for-telegram-login.ts",
"timestamp": 1738073593695
"title": "1738072787797-add-activated-field-to-modules.ts",
"timestamp": 1744199444528
}
]
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@notionhq/client": "^2.2.3",
"@sentry/node": "^7.50.0",
"@temporalio/client": "^1.11.3",
"@togethercrew.dev/db": "^3.3.0",
"@togethercrew.dev/db": "^3.4.0",
"@togethercrew.dev/tc-messagebroker": "^0.0.50",
"@types/express-session": "^1.17.7",
"@types/morgan": "^1.9.5",
Expand Down
1 change: 0 additions & 1 deletion src/controllers/hivemind.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import HivemindTemporalService from '../services/temporal/hivemind.service';
import { catchAsync } from '../utils';

const askQuestion = catchAsync(async function (req: IAuthRequest, res: Response) {
console.debug('Body', req.body.communityId, req.body.question, req.body.chatId);
req.setTimeout(6 * 60 * 1000);
res.setTimeout(6 * 60 * 1000);
const answer = await HivemindTemporalService.triggerWorkflow(
Expand Down

This file was deleted.

29 changes: 29 additions & 0 deletions src/migrations/db/1738072787797-add-activated-field-to-modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dotenv/config';

import mongoose from 'mongoose';

import { Module } from '@togethercrew.dev/db';

import config from '../../config';
import logger from '../../config/logger';

async function connectToMongoDB() {
try {
await mongoose.connect(config.mongoose.serverURL);
logger.info('Connected to MongoDB!');
} catch (error) {
logger.fatal('Failed to connect to MongoDB!');
throw error;
}
}

export const up = async () => {
await connectToMongoDB();

const result = await Module.updateMany({}, { $set: { activated: true } });
logger.info(`Up migration: added activated field to ${result.modifiedCount} module(s).`);

await mongoose.connection.close();
};

export const down = async () => {};
12 changes: 4 additions & 8 deletions src/services/module.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FilterQuery, HydratedDocument, ObjectId, Types } from 'mongoose';

import { IModule, IModuleUpdateBody, Module, ModuleNames, PlatformNames } from '@togethercrew.dev/db';
import { IModule, IModuleUpdateBody, Module } from '@togethercrew.dev/db';

import platformService from './platform.service';
import websiteService from './website';
Expand Down Expand Up @@ -87,15 +87,11 @@ const updateModule = async (

for (const newPlatform of platforms) {
const existingPlatform = module.options.platforms.find((p) => p.name === newPlatform.name);
console.log('S4', existingPlatform);

if (existingPlatform) {
console.log('A1', module.name, newPlatform.name);
if (module.name === ModuleNames.Hivemind && newPlatform.name === PlatformNames.Website) {
console.log('A2');

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);
Expand Down
1 change: 0 additions & 1 deletion src/services/platform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ const updatePlatform = async (
await platformService.notifyDiscordUserImportComplete(platform.id, discordIdentity.id);
}
}
console.log('Main', updateBody);

if (updateBody.metadata) {
updateBody.metadata = {
Expand Down
9 changes: 8 additions & 1 deletion src/validations/module.validation.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,6 +15,7 @@ const createModule = {
.required()
.valid(...Object.values(ModuleNames)),
community: Joi.string().custom(objectId).required(),
activated: Joi.boolean().required(),
}),
};

Expand Down Expand Up @@ -202,20 +206,23 @@ const dynamicModuleUpdate = (req: any) => {
bodyOption = {
body: Joi.object().required().keys({
options: hivemindOptions(),
activated: Joi.boolean(),
}),
};
break;
case ModuleNames.ViolationDetection:
bodyOption = {
body: Joi.object().required().keys({
options: violationDetectionOptions(),
activated: Joi.boolean(),
}),
};
break;
case ModuleNames.DynamicNft:
bodyOption = {
body: Joi.object().required().keys({
options: dynamicNftOptions(),
activated: Joi.boolean(),
}),
};
break;
Expand Down