Skip to content
Snippets Groups Projects
Select Git revision
  • develop default protected
  • issue/68-govbr
  • Issue-25/swagger
  • Issue/58-adjustments
  • 52-criar-rota-de-publicar-recurso
  • 57-rotas-s3
  • issue-49/criar-rotas-de-usuarios
  • 48-criar-rotas-de-recursos
  • issue-22/create-complaints-table
  • issue-2/translate-schemas
10 results

notification.ts

Blame
  • notification.ts 1.95 KiB
    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