Skip to content

Commit

Permalink
delete sticker listener, update session schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Roznov authored and Aleksei Roznov committed Oct 8, 2024
1 parent 55c45c3 commit 8771589
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bot/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class UpdateListeners {

@On("sticker")
async onSticker(@Ctx() ctx: Context) {
await ctx.reply("👍");
// await ctx.reply("👍");
}

@Hears("hi")
Expand Down
6 changes: 5 additions & 1 deletion src/db/schemas/session.schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { HydratedDocument } from "mongoose";

@Schema({ expires: "7d" })
@Schema({ timestamps: true }) // Enables `createdAt` and `updatedAt` fields automatically
export class Session {
@Prop({ required: true })
type: string;
Expand All @@ -11,6 +11,10 @@ export class Session {

@Prop({ required: true })
option: string;

@Prop({ default: Date.now, expires: "7d" }) // TTL index with expiration after 7 days
createdAt: Date; // MongoDB uses this field for the TTL
}

export type TSession = HydratedDocument<Session>;
export const SessionSchema = SchemaFactory.createForClass(Session);
2 changes: 1 addition & 1 deletion src/db/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class TaskService implements ITask {

async deleteAllTasksForJob(jobId: string): Promise<void> {
await this.taskModel.deleteMany({
_id: jobId,
_id: jobId, // BUG - there should be jobId in the task scheme
status: {
$in: [taskStatus.new, taskStatus.snoozed, taskStatus.pending],
},
Expand Down
154 changes: 154 additions & 0 deletions src/notebook.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"update_id": 396065464,
"my_chat_member": {
"chat": {
"id": -892251879,
"title": "Дикари",
"type": "group",
"all_members_are_administrators": true
},
"from": {
"id": 268482275,
"is_bot": false,
"first_name": "uncle Lyozha",
"username": "Lyozha",
"language_code": "en"
},
"date": 1719910633,
"old_chat_member": {
"user": {
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
},
"status": "left"
},
"new_chat_member": {
"user": {
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
},
"status": "member"
}
}
},
{
"update_id": 396065465,
"message": {
"message_id": 2487,
"from": {
"id": 268482275,
"is_bot": false,
"first_name": "uncle Lyozha",
"username": "Lyozha",
"language_code": "en"
},
"chat": {
"id": -892251879,
"title": "Дикари",
"type": "group",
"all_members_are_administrators": true
},
"date": 1719910633,
"new_chat_participant": {
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
},
"new_chat_member": {
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
},
"new_chat_members": [
{
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
}
]
}
}
User with 7035486003 not found in DB.
New user created:
{
userName: 'testLyozhaBot',
tgId: 7035486003,
_id: new ObjectId('6683c0e9362e888122b1eb59'),
__v: 0
}
{
"update_id": 396065466,
"my_chat_member": {
"chat": {
"id": -892251879,
"title": "Дикари",
"type": "group",
"all_members_are_administrators": true
},
"from": {
"id": 268482275,
"is_bot": false,
"first_name": "uncle Lyozha",
"username": "Lyozha",
"language_code": "en"
},
"date": 1719910650,
"old_chat_member": {
"user": {
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
},
"status": "member"
},
"new_chat_member": {
"user": {
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
},
"status": "left"
}
}
}
{
"update_id": 396065467,
"message": {
"message_id": 2489,
"from": {
"id": 268482275,
"is_bot": false,
"first_name": "uncle Lyozha",
"username": "Lyozha",
"language_code": "en"
},
"chat": {
"id": -892251879,
"title": "Дикари",
"type": "group",
"all_members_are_administrators": true
},
"date": 1719910650,
"left_chat_participant": {
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
},
"left_chat_member": {
"id": 7035486003,
"is_bot": true,
"first_name": "test_lyozha_bot",
"username": "testLyozhaBot"
}
}
}
2 changes: 1 addition & 1 deletion src/scenes/assignUser.wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class AssignUserWizard {
await ctx.editMessageText(errMsgGeneral);
}
const pmMsg =
"New task created: \n" + newTask.jobName + " = " + newTask.userName;
"The user on duty has been changed: \n" + newTask.jobName + " = " + newTask.userName;
await ctx.editMessageText(pmMsg);
await ctx.scene.leave();
}
Expand Down

0 comments on commit 8771589

Please sign in to comment.