This commit is contained in:
34
src/db/schema/strike.ts
Normal file
34
src/db/schema/strike.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { int, mysqlTable, timestamp } from 'drizzle-orm/mysql-core';
|
||||
import { strikeReason } from '@db/schema/strikeReason.ts';
|
||||
import type { MySql2Database } from 'drizzle-orm/mysql2';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { report } from '@db/schema/report.ts';
|
||||
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(),
|
||||
strikeReasonId: int('strike_reason_id')
|
||||
.notNull()
|
||||
.references(() => strikeReason.id)
|
||||
});
|
||||
|
||||
export type GetStrikesByTeamId = {
|
||||
teamId: number;
|
||||
};
|
||||
|
||||
export async function getStrikesByTeamId(db: Database, values: GetStrikesByTeamId) {
|
||||
return db
|
||||
.select({
|
||||
id: strike.id,
|
||||
at: strike.at,
|
||||
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));
|
||||
}
|
Reference in New Issue
Block a user