Skip to content

Commit

Permalink
feat: started report service
Browse files Browse the repository at this point in the history
  • Loading branch information
darklight9811 committed Jul 19, 2024
1 parent b6d817c commit 86acf58
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/schemas/src/schemas/report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from "zod";

const report = z.object({
reason: z.enum(["offensive", "not_missing", "ownership", "other"]),
description: z.string().optional(),
});

export default report;

export type Report = z.infer<typeof report>;
44 changes: 44 additions & 0 deletions packages/services/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ generator client {
provider = "prisma-client-js"
}

// ---------------
// #MARK: Enums
// ---------------

enum EntityType {
person
animal
Expand All @@ -21,6 +25,17 @@ enum Gender {
other
}

enum ReportReason {
offensive
not_missing
ownership
other
}

// ---------------
// #MARK: Base models
// ---------------

model User {
id String @id @default(cuid())
name String?
Expand All @@ -31,9 +46,16 @@ model User {
auth_provider String @default("password")
auth_value String
reports_created Report[] @relation(name: "user_created")
reports Report[] @relation(name: "user")
@@map("users")
}

// ---------------
// #MARK: Profile related
// ---------------

model Entity {
id String @id @default(cuid())
Expand All @@ -53,6 +75,7 @@ model Entity {
addresses EntityAddress[]
data EntityData?
contact EntityContact?
Report Report[]
@@map("entities")
}
Expand Down Expand Up @@ -111,3 +134,24 @@ model EntityContact {
@@map("entity_contact")
}

// ---------------
// #MARK: Report
// ---------------

model Report {
id String @id @default(cuid())
reason ReportReason
description String @default("")
id_user_created String?
id_entity String?
id_user String?
entity Entity? @relation(fields: [id_entity], references: [id], onDelete: Cascade)
user User? @relation(name: "user", fields: [id_user], references: [id], onDelete: Cascade)
user_created User? @relation(name: "user_created", fields: [id_user_created], references: [id], onDelete: SetNull)
@@map("reports")
}
32 changes: 32 additions & 0 deletions packages/services/src/services/report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Pagination } from "@repo/schemas/pagination";
import type { Report } from "@repo/schemas/report";
import { db } from "../lib/db";
import service from "../lib/service";

const reportService = service({
index({ page, limit }: Pagination) {
return db.report.paginate({
page,
limit,
});
},

create(data: Report, { user }) {
if (user?.id) return user;

return db.report.create({
data: {
reason: data.reason,
description: data.description,
},
});
},

show(id?: string | null) {
if (!id) return undefined;

return db.report.findUnique({ where: { id } });
},
});

export default reportService;

0 comments on commit 86acf58

Please sign in to comment.