diff --git a/src/db/schema/achievements.schema.ts b/src/db/schema/achievements.schema.ts index 16b18c7e540c2becebe89e7c7df8909f2a4e7595..154c2128685cd0a31fb08076b0e348d3bc1e8846 100644 --- a/src/db/schema/achievements.schema.ts +++ b/src/db/schema/achievements.schema.ts @@ -2,7 +2,7 @@ import { sql } from "drizzle-orm"; import { boolean, integer, numeric, pgTable, serial, text, timestamp, varchar } from "drizzle-orm/pg-core"; import { createInsertSchema, createSelectSchema } from "drizzle-zod"; import { z } from "zod"; -import stateEnum from "./stateEnum.schema"; +import stateEnum from "./state-enum.schema"; export const achievementTable = pgTable('achievements', { id: serial('id').primaryKey() diff --git a/src/db/schema/complaint.schema.ts b/src/db/schema/complaint.schema.ts index d447a641453d5680d5161c1c9f5413c99feb604b..fb87f519f1016a39e4fad1c5a1a91e0e56e880d3 100644 --- a/src/db/schema/complaint.schema.ts +++ b/src/db/schema/complaint.schema.ts @@ -4,7 +4,7 @@ import { createInsertSchema, createSelectSchema } from "drizzle-zod"; import type { z } from "zod"; import resourceTable from "./resource.schema"; import collectionTable from "./collections.schema"; -import stateEnum from "./stateEnum.schema"; +import stateEnum from "./state-enum.schema"; const complaintTable = pgTable('complaints', { id: serial('id').primaryKey() diff --git a/src/db/schema/index.ts b/src/db/schema/index.ts index afcfe60c4d6ac74c0423280f91fc9952e3c227e5..aef7b5ed9bb9ec2f1915b9c438b9fde604c77b33 100644 --- a/src/db/schema/index.ts +++ b/src/db/schema/index.ts @@ -28,8 +28,8 @@ import userAchievementsTable from '../relations/user-achievement.relation' import actionTable from './actions.schema' import notificationRelationTable from '../relations/notification.relation' import userItemRelationTable from '../relations/user-item.relation' -import stateEnum from './stateEnum.schema' -import resourceEnum from './resourceEnum.schema' +import stateEnum from './state-enum.schema' +import resourceEnum from './resource-enum.schema' import commentsTable from './comments.schema' import commentReplyTable from './comment-reply.schema' import userCollectionTable from '../relations/user-collection.relation' diff --git a/src/db/schema/notification.ts b/src/db/schema/notification.ts new file mode 100644 index 0000000000000000000000000000000000000000..9ec4fe87b3d1add3614c914bd8edfb1ef90ec8c0 --- /dev/null +++ b/src/db/schema/notification.ts @@ -0,0 +1,52 @@ +import { sql } from "drizzle-orm" +import { integer, pgTable, serial, timestamp } from "drizzle-orm/pg-core" +import { createInsertSchema, createSelectSchema } from "drizzle-zod" +import type { z } from "zod" +import { actionTable, collectionTable, resourceTable, userTable } from "." + +const notificationTable = pgTable('notifications', { + id: serial('id').primaryKey() + .unique() + .notNull(), + action_id: integer('action_id') + .references(() => actionTable.id, {onDelete: 'cascade'}) + .notNull(), + actor_user_id: integer('actor_user_id') + .references(() => userTable.id, {onDelete: 'cascade'}) + .notNull(), + target_user_id: integer('target_user_id') + .references(() => userTable.id, {onDelete: 'cascade'}) + .notNull(), + target_resource_id: integer('target_resource_id') + .references(() => resourceTable.id, {onDelete: 'cascade'}), + target_collection_id: integer('target_collection_id') + .references(() => collectionTable.id, {onDelete: 'cascade'}), + createdAt: timestamp('created_at', { mode: 'string' }) + .notNull() + .defaultNow(), + updatedAt: timestamp('updated_at', { mode: 'string' }) + .notNull() + .defaultNow() + .$onUpdate(() => sql`current_timestamp`), +}) + +const notificationModelSchema = createSelectSchema(notificationTable) +const notificationDtoSchema = notificationModelSchema +const notificationInputSchema = createInsertSchema(notificationTable) +const notificationUpdateSchema = notificationInputSchema + .partial() + .required({ id: true }) + +export type NotificationModel = z.infer<typeof notificationModelSchema> +export type NotificationDto = z.infer<typeof notificationDtoSchema> +export type NotificationInput = z.infer<typeof notificationInputSchema> +export type NotificationUpdate = z.infer<typeof notificationUpdateSchema> + +export const notificationSchemas = { + model: notificationModelSchema, + dto: notificationDtoSchema, + input: notificationInputSchema, + update: notificationUpdateSchema +} + +export default notificationTable \ No newline at end of file diff --git a/src/db/schema/resourceEnum.schema.ts b/src/db/schema/resource-enum.schema.ts similarity index 100% rename from src/db/schema/resourceEnum.schema.ts rename to src/db/schema/resource-enum.schema.ts diff --git a/src/db/schema/resource.schema.ts b/src/db/schema/resource.schema.ts index 7e8a99c5b35661490798255eefc294b419ef787a..7430eaeb9eb59e2615df00cfad97ede86941def9 100644 --- a/src/db/schema/resource.schema.ts +++ b/src/db/schema/resource.schema.ts @@ -17,7 +17,7 @@ import userTable from './user.schema' import objectTypeTable from './object-type.schema' import licenseTable from './license.schema' import resourceStatsTable from './resource-stats.schema' -import resourceEnum from './resourceEnum.schema' +import resourceEnum from './resource-enum.schema' //por padrao active é false, só é true quando o recurso é aprovado const resourceTable = pgTable('resources', { diff --git a/src/db/schema/stateEnum.schema.ts b/src/db/schema/state-enum.schema.ts similarity index 100% rename from src/db/schema/stateEnum.schema.ts rename to src/db/schema/state-enum.schema.ts