update reports
All checks were successful
deploy / build-and-deploy (/testvaro, /opt/website-test, website-test) (push) Successful in 21s
deploy / build-and-deploy (/varo, /opt/website, website) (push) Successful in 13s

This commit is contained in:
2025-06-10 00:03:38 +02:00
parent 8262fd90aa
commit 5c41857530
11 changed files with 253 additions and 50 deletions

View File

@ -8,27 +8,50 @@ import { reportStatus } from '@db/schema/reportStatus.ts';
type Database = MySql2Database<{ strike: typeof strike }>;
export const strike = mysqlTable('strike', {
id: int('id').primaryKey().autoincrement(),
at: timestamp('at', { mode: 'string' }).notNull(),
at: timestamp('at', { mode: 'date' }).notNull(),
reportId: int('report_id')
.notNull()
.references(() => report.id),
strikeReasonId: int('strike_reason_id')
.notNull()
.references(() => strikeReason.id)
});
export type GetStrikesByTeamId = {
export type EditStrikeReq = {
reportId: number;
at?: Date;
strikeReasonId: number;
};
export type GetStrikesByTeamIdReq = {
teamId: number;
};
export async function getStrikesByTeamId(db: Database, values: GetStrikesByTeamId) {
export async function editStrike(db: Database, values: EditStrikeReq) {
return db
.insert(strike)
.values({
at: values.at ?? new Date(),
reportId: values.reportId,
strikeReasonId: values.strikeReasonId
})
.onDuplicateKeyUpdate({
set: {
at: values.at ?? new Date(),
strikeReasonId: values.strikeReasonId
}
});
}
export async function getStrikesByTeamId(db: Database, values: GetStrikesByTeamIdReq) {
return db
.select({
id: strike.id,
at: strike.at,
report: report,
reason: strikeReason
})
.from(strike)
.innerJoin(strikeReason, eq(strike.strikeReasonId, strikeReason.id))
.innerJoin(reportStatus, eq(strike.id, reportStatus.strikeId))
.innerJoin(report, eq(reportStatus.reportId, report.id))
.where(eq(report.reportedTeamId, values.teamId));
}