Skip to content

Commit 7b75503

Browse files
committed
feat(decorators): add initGroupSetting decorator for group settings initialization
- Implemented `initGroupSetting` decorator to initialize group settings - Ensures that group settings are fetched or initialized before method execution - Uses `GroupSettingsService` to manage group settings based on the chat ID
1 parent 2374cce commit 7b75503

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/decorators/db/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Context } from "grammy";
2+
import { GroupSettingsService } from "../../service/db/group";
3+
export function initGroupSetting() {
4+
return function (
5+
target: any,
6+
propertyKey: string,
7+
descriptor: PropertyDescriptor
8+
) {
9+
const originalMethod = descriptor.value;
10+
11+
descriptor.value = async function (...args: any[]) {
12+
const ctx: Context = (this as any)?.ctx || args[0];
13+
const groupSettingsRepo = new GroupSettingsService();
14+
const groupSettings = await groupSettingsRepo.getByGroupId(ctx.chat?.id!);
15+
if (!groupSettings) {
16+
await groupSettingsRepo.init(ctx);
17+
}
18+
19+
return originalMethod.apply(this, args);
20+
};
21+
22+
return descriptor;
23+
};
24+
}

0 commit comments

Comments
 (0)