fix report edit
This commit is contained in:
@ -151,6 +151,8 @@ export const report = {
|
|||||||
reportId: input.reportId,
|
reportId: input.reportId,
|
||||||
strikeReasonId: input.strikeReasonId
|
strikeReasonId: input.strikeReasonId
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
await db.deleteStrike({ reportId: input.reportId });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@
|
|||||||
let status = $state<'open' | 'closed' | null>(null);
|
let status = $state<'open' | 'closed' | null>(null);
|
||||||
let notice = $state<string | null>(null);
|
let notice = $state<string | null>(null);
|
||||||
let statement = $state<string | null>(null);
|
let statement = $state<string | null>(null);
|
||||||
let strikeReason = $state<string | null>(null);
|
let strikeReason = $state<string | null>(String(report?.strike?.strikeReasonId ?? null));
|
||||||
|
|
||||||
// consts
|
// consts
|
||||||
const strikeReasonValues = strikeReasons.reduce(
|
const strikeReasonValues = strikeReasons.reduce(
|
||||||
(prev, curr) => Object.assign(prev, { [curr.id]: `${curr.name} (${curr.weight})` }),
|
(prev, curr) => Object.assign(prev, { [curr.id]: `${curr.name} (${curr.weight})` }),
|
||||||
{}
|
{ [null]: 'Kein Vergehen' }
|
||||||
);
|
);
|
||||||
|
|
||||||
// lifetime
|
// lifetime
|
||||||
@ -82,8 +82,7 @@
|
|||||||
label="Bearbeitungsstatus"
|
label="Bearbeitungsstatus"
|
||||||
dynamicWidth
|
dynamicWidth
|
||||||
/>
|
/>
|
||||||
<Select bind:value={strikeReason} values={strikeReasonValues} defaultValue="" label="Vergehen" dynamicWidth
|
<Select bind:value={strikeReason} values={strikeReasonValues} label="Vergehen" dynamicWidth></Select>
|
||||||
></Select>
|
|
||||||
<div class="divider mt-0 mb-2"></div>
|
<div class="divider mt-0 mb-2"></div>
|
||||||
<button class="btn mt-auto" onclick={onSaveButtonClick}>Speichern</button>
|
<button class="btn mt-auto" onclick={onSaveButtonClick}>Speichern</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Snippet } from 'svelte';
|
import type { Snippet } from 'svelte';
|
||||||
|
|
||||||
|
// types
|
||||||
interface Props {
|
interface Props {
|
||||||
id?: string;
|
id?: string;
|
||||||
value?: string | null;
|
value?: string | null;
|
||||||
@ -19,6 +20,7 @@
|
|||||||
notice?: Snippet;
|
notice?: Snippet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inputs
|
||||||
let {
|
let {
|
||||||
id,
|
id,
|
||||||
value = $bindable(),
|
value = $bindable(),
|
||||||
|
@ -130,6 +130,8 @@ import {
|
|||||||
deleteStrikeReason
|
deleteStrikeReason
|
||||||
} from '@db/schema/strikeReason.ts';
|
} from '@db/schema/strikeReason.ts';
|
||||||
import {
|
import {
|
||||||
|
deleteStrike,
|
||||||
|
type DeleteStrikeReq,
|
||||||
editStrike,
|
editStrike,
|
||||||
type EditStrikeReq,
|
type EditStrikeReq,
|
||||||
getStrikeByReportId,
|
getStrikeByReportId,
|
||||||
@ -288,6 +290,7 @@ export class Database {
|
|||||||
|
|
||||||
/* strikes */
|
/* strikes */
|
||||||
editStrike = (values: EditStrikeReq) => editStrike(this.db, values);
|
editStrike = (values: EditStrikeReq) => editStrike(this.db, values);
|
||||||
|
deleteStrike = (values: DeleteStrikeReq) => deleteStrike(this.db, values);
|
||||||
getStrikeByReportId = (values: GetStrikeByReportIdReq) => getStrikeByReportId(this.db, values);
|
getStrikeByReportId = (values: GetStrikeByReportIdReq) => getStrikeByReportId(this.db, values);
|
||||||
getStrikesByTeamId = (values: GetStrikesByTeamIdReq) => getStrikesByTeamId(this.db, values);
|
getStrikesByTeamId = (values: GetStrikesByTeamIdReq) => getStrikesByTeamId(this.db, values);
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import { reportStatus } from './reportStatus.ts';
|
|||||||
import { generateRandomString } from '@util/random.ts';
|
import { generateRandomString } from '@util/random.ts';
|
||||||
import { team } from '@db/schema/team.ts';
|
import { team } from '@db/schema/team.ts';
|
||||||
import { BASE_PATH } from 'astro:env/server';
|
import { BASE_PATH } from 'astro:env/server';
|
||||||
|
import { strikeReason } from '@db/schema/strikeReason.ts';
|
||||||
|
import { strike } from '@db/schema/strike.ts';
|
||||||
|
|
||||||
type Database = MySql2Database<{ report: typeof report }>;
|
type Database = MySql2Database<{ report: typeof report }>;
|
||||||
|
|
||||||
@ -113,12 +115,17 @@ export async function getReports(db: Database, values: GetReportsReq) {
|
|||||||
status: reportStatus.status,
|
status: reportStatus.status,
|
||||||
notice: reportStatus.notice,
|
notice: reportStatus.notice,
|
||||||
statement: reportStatus.statement
|
statement: reportStatus.statement
|
||||||
|
},
|
||||||
|
strike: {
|
||||||
|
strikeReasonId: strikeReason.id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.from(report)
|
.from(report)
|
||||||
.innerJoin(reporterTeam, eq(report.reporterTeamId, reporterTeam.id))
|
.innerJoin(reporterTeam, eq(report.reporterTeamId, reporterTeam.id))
|
||||||
.leftJoin(reportedTeam, eq(report.reportedTeamId, reportedTeam.id))
|
.leftJoin(reportedTeam, eq(report.reportedTeamId, reportedTeam.id))
|
||||||
.leftJoin(reportStatus, eq(report.id, reportStatus.reportId))
|
.leftJoin(reportStatus, eq(report.id, reportStatus.reportId))
|
||||||
|
.leftJoin(strike, eq(report.id, strike.reportId))
|
||||||
|
.leftJoin(strikeReason, eq(strike.strikeReasonId, strikeReason.id))
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
values.reporter != null ? eq(report.reporterTeamId, reporterIdSubquery!.id) : undefined,
|
values.reporter != null ? eq(report.reporterTeamId, reporterIdSubquery!.id) : undefined,
|
||||||
|
@ -3,7 +3,6 @@ import { strikeReason } from '@db/schema/strikeReason.ts';
|
|||||||
import type { MySql2Database } from 'drizzle-orm/mysql2';
|
import type { MySql2Database } from 'drizzle-orm/mysql2';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import { report } from '@db/schema/report.ts';
|
import { report } from '@db/schema/report.ts';
|
||||||
import { strikeReasons } from '@app/admin/strikeReasons/strikeReasons.ts';
|
|
||||||
|
|
||||||
type Database = MySql2Database<{ strike: typeof strike }>;
|
type Database = MySql2Database<{ strike: typeof strike }>;
|
||||||
|
|
||||||
@ -23,6 +22,10 @@ export type EditStrikeReq = {
|
|||||||
strikeReasonId: number;
|
strikeReasonId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DeleteStrikeReq = {
|
||||||
|
reportId: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type GetStrikeByReportIdReq = {
|
export type GetStrikeByReportIdReq = {
|
||||||
reportId: number;
|
reportId: number;
|
||||||
};
|
};
|
||||||
@ -47,6 +50,10 @@ export async function editStrike(db: Database, values: EditStrikeReq) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteStrike(db: Database, values: DeleteStrikeReq) {
|
||||||
|
return db.delete(strike).where(eq(strike.reportId, values.reportId)).limit(1);
|
||||||
|
}
|
||||||
|
|
||||||
export async function getStrikeByReportId(db: Database, values: GetStrikeByReportIdReq) {
|
export async function getStrikeByReportId(db: Database, values: GetStrikeByReportIdReq) {
|
||||||
const strikes = await db
|
const strikes = await db
|
||||||
.select({
|
.select({
|
||||||
|
Reference in New Issue
Block a user