Skip to content

Commit

Permalink
Add schedule data to bot fetch api. (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmoy12c authored Aug 1, 2024
1 parent b5b7fda commit 60d8f2b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- Changed the type of `botId` on the `Schedules` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
*/
-- AlterTable
ALTER TABLE "Schedules" DROP COLUMN "botId",
ADD COLUMN "botId" UUID NOT NULL;

-- AddForeignKey
ALTER TABLE "Schedules" ADD CONSTRAINT "Schedules_botId_fkey" FOREIGN KEY ("botId") REFERENCES "Bot"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
8 changes: 5 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ model Bot {
tags String[]
botImage String?
meta Json?
schedules Schedules[]
}

model UserSegment {
Expand Down Expand Up @@ -134,10 +135,11 @@ model ConversationLogic {
}

model Schedules {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
createdAt DateTime @default(now())
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid()
createdAt DateTime @default(now())
scheduledAt DateTime
authToken String
botId String
bot Bot @relation(fields: [botId], references: [id])
config Json
botId String @db.Uuid
}
4 changes: 4 additions & 0 deletions src/modules/bot/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class BotService implements OnModuleInit {
adapter: true,
},
},
schedules: {},
};

pause(id: string) {
Expand Down Expand Up @@ -200,6 +201,7 @@ export class BotService implements OnModuleInit {
this.schedulerRegistry.addCronJob(`notification_${randomUUID()}`, job);
job.start();
this.logger.log(`Scheduled notification for: ${botId}, at: ${scheduledTime.toDateString()}`);
await this.cacheManager.reset();
}

// dateString = '2020-01-01'
Expand Down Expand Up @@ -349,6 +351,7 @@ export class BotService implements OnModuleInit {
adapter: true;
};
};
schedules: {},
};
}>[]> {
const startTime = performance.now();
Expand Down Expand Up @@ -446,6 +449,7 @@ export class BotService implements OnModuleInit {
adapter: true;
};
};
schedules: {},
};
}> | null> {
const startTime = performance.now();
Expand Down

0 comments on commit 60d8f2b

Please sign in to comment.