mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 16:06:59 +01:00
fix #3, now tracking cheers and cheerEvents in database, minor tweaks to existing code
This commit is contained in:
@@ -34,11 +34,26 @@ export type timeoutRecord = {
|
||||
created: string;
|
||||
};
|
||||
|
||||
export type cheerEventRecord = {
|
||||
id?: string;
|
||||
user: string;
|
||||
cheer: string;
|
||||
created: string;
|
||||
};
|
||||
|
||||
export type cheerRecord = {
|
||||
id?: string;
|
||||
user?: string;
|
||||
amount: number;
|
||||
};
|
||||
|
||||
interface TypedPocketBase extends PocketBase {
|
||||
collection(idOrName: 'auth'): RecordService<authRecord>;
|
||||
collection(idOrName: 'users'): RecordService<userRecord>;
|
||||
collection(idOrName: 'usedItems'): RecordService<usedItemRecord>;
|
||||
collection(idOrName: 'timeouts'): RecordService<timeoutRecord>;
|
||||
collection(idOrName: 'cheerEvents'): RecordService<cheerEventRecord>;
|
||||
collection(idOrName: 'cheers'): RecordService<cheerRecord>;
|
||||
};
|
||||
|
||||
export default new PocketBase(pocketbaseurl).autoCancellation(false) as TypedPocketBase;
|
||||
|
||||
26
src/db/dbCheerEvents.ts
Normal file
26
src/db/dbCheerEvents.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import pocketbase from "db/connection";
|
||||
import User from "user";
|
||||
import logger from "lib/logger";
|
||||
const pb = pocketbase.collection('cheerEvents');
|
||||
|
||||
export async function createCheerEventRecord(user: User, cheer: string): Promise<void> {
|
||||
try {
|
||||
await pb.create({ user: user.id, cheer });
|
||||
} catch (e) {
|
||||
logger.err(`Failed to create cheerEvent record in database: user: ${user.id}, cheer: ${cheer}`);
|
||||
logger.err(e as string);
|
||||
};
|
||||
};
|
||||
|
||||
export async function getCheerEvents(user: User, monthData?: string) {
|
||||
try {
|
||||
const monthquery = monthData ? ` && created~"${monthData}"` : '';
|
||||
const data = await pb.getFullList({
|
||||
filter: `user="${user.id}"${monthquery}`
|
||||
});
|
||||
return data;
|
||||
} catch (e) {
|
||||
logger.err(`Failed to get cheerEvents for user: ${user.id}, month: ${monthData}`);
|
||||
logger.err(e as string);
|
||||
};
|
||||
};
|
||||
26
src/db/dbCheers.ts
Normal file
26
src/db/dbCheers.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import pocketbase from "db/connection";
|
||||
import User from "user";
|
||||
import logger from "lib/logger";
|
||||
const pb = pocketbase.collection('cheers');
|
||||
|
||||
export async function createCheerRecord(user: User, amount: number): Promise<void> {
|
||||
try {
|
||||
await pb.create({ user: user.id, amount })
|
||||
} catch (e) {
|
||||
logger.err(`Failed to create cheer record in database: user: ${user.id}, amount: ${amount}`);
|
||||
logger.err(e as string);
|
||||
};
|
||||
};
|
||||
|
||||
export async function getCheers(user: User, monthData?: string) {
|
||||
try {
|
||||
const monthquery = monthData ? ` && created~"${monthData}"` : '';
|
||||
const data = await pb.getFullList({
|
||||
filter: `user="${user.id}"${monthquery}`
|
||||
});
|
||||
return data;
|
||||
} catch (e) {
|
||||
logger.err(`Failed to get cheers for user: ${user.id}, month: ${monthData}`);
|
||||
logger.err(e as string);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user