diff --git a/backend/app/schemas/AccesLogSchema.js b/backend/app/schemas/AccesLogSchema.js index 0143c514..3e5cd321 100644 --- a/backend/app/schemas/AccesLogSchema.js +++ b/backend/app/schemas/AccesLogSchema.js @@ -1,9 +1,11 @@ const { z } = require('zod') +const UserSchema = require('./UserSchema') const AccesLogSchema = z.object({ id: z.number().int(), login: z.date(), logout: z.date(), + user: UserSchema, userId: z.number().int(), }) diff --git a/backend/app/schemas/AdStatusSchema.js b/backend/app/schemas/AdStatusSchema.js index 85c159b7..8e446837 100644 --- a/backend/app/schemas/AdStatusSchema.js +++ b/backend/app/schemas/AdStatusSchema.js @@ -1,10 +1,12 @@ const { z } = require('zod') +const AdsSchema = require('./AdsSchema') const AdStatusSchema = z.object({ id: z.number().int(), name: z.string(), unPublish: z.number().int(), publish: z.number().int(), + ads: AdsSchema.array(), }) module.exports = AdStatusSchema diff --git a/backend/app/schemas/AdTypeSchema.js b/backend/app/schemas/AdTypeSchema.js index 37d89ade..33b2686a 100644 --- a/backend/app/schemas/AdTypeSchema.js +++ b/backend/app/schemas/AdTypeSchema.js @@ -1,4 +1,5 @@ const { z } = require('zod') +const AdsSchema = require('./AdsSchema') const AdTypeSchema = z.object({ id: z.number().int(), @@ -11,6 +12,7 @@ const AdTypeSchema = z.object({ warehouse: z.number().int(), building: z.number().int(), newBuilding: z.number().int(), + ads: AdsSchema.array(), }) module.exports = AdTypeSchema diff --git a/backend/app/schemas/AdsSchema.js b/backend/app/schemas/AdsSchema.js index 38d8da06..70be845a 100644 --- a/backend/app/schemas/AdsSchema.js +++ b/backend/app/schemas/AdsSchema.js @@ -1,7 +1,12 @@ const { z } = require('zod') +const UserSchema = require('./UserSchema') +const AdTypeSchema = require('./AdTypeSchema') +const AdStatusSchema = require('./AdStatusSchema') +const MediaSchema = require('./MediaSchema') const AdsSchema = z.object({ id: z.number().int(), + user: UserSchema, userId: z.number().int(), title: z.string(), description: z.string(), @@ -13,10 +18,13 @@ const AdsSchema = z.object({ city: z.string(), mapLat: z.number(), mapLon: z.number(), + adType: AdTypeSchema, adTypeId: z.number().int(), + adStatus: AdStatusSchema, adStatusId: z.number().int(), createdAt: z.date().optional(), updatedAt: z.date(), + media: MediaSchema.array(), }) module.exports = AdsSchema diff --git a/backend/app/schemas/ConversationSchema.js b/backend/app/schemas/ConversationSchema.js index 16c763d0..736aebe9 100644 --- a/backend/app/schemas/ConversationSchema.js +++ b/backend/app/schemas/ConversationSchema.js @@ -1,7 +1,11 @@ const { z } = require('zod') +const MessageSchema = require('./MessageSchema') +const UserConversationSchema = require('./UserConversationSchema') const ConversationSchema = z.object({ id: z.number().int(), + messages: MessageSchema.array(), + participants: UserConversationSchema.array(), }) module.exports = ConversationSchema diff --git a/backend/app/schemas/InvoiceSchema.js b/backend/app/schemas/InvoiceSchema.js index 3ef3a7a0..93184c6c 100644 --- a/backend/app/schemas/InvoiceSchema.js +++ b/backend/app/schemas/InvoiceSchema.js @@ -1,7 +1,10 @@ const { z } = require('zod') +const { Status } = require('@prisma/client') +const UserSchema = require('./UserSchema') const InvoiceSchema = z.object({ id: z.number().int(), + user: UserSchema, userId: z.number().int(), billingAddress: z.string().nullish(), postalCode: z.string().nullish(), @@ -13,6 +16,7 @@ const InvoiceSchema = z.object({ secondTax: z.number().int(), createdAt: z.date().optional(), invoiceNumber: z.string(), + status: z.nativeEnum(Status).optional(), }) module.exports = InvoiceSchema diff --git a/backend/app/schemas/LevelSchema.js b/backend/app/schemas/LevelSchema.js index ffa2cd19..f68baf41 100644 --- a/backend/app/schemas/LevelSchema.js +++ b/backend/app/schemas/LevelSchema.js @@ -1,9 +1,13 @@ const { z } = require('zod') +const LevelTypeSchema = require('./LevelTypeSchema') const LevelSchema = z.object({ id: z.number().int(), name: z.string(), + parent: z.lazy(() => LevelSchema).optional(), parentId: z.number().int().nullish(), + child: z.lazy(() => LevelSchema).array(), + levelType: LevelTypeSchema, levelTypeId: z.number().int(), }) diff --git a/backend/app/schemas/LevelTypeSchema.js b/backend/app/schemas/LevelTypeSchema.js index 4daa1f81..1f3beb72 100644 --- a/backend/app/schemas/LevelTypeSchema.js +++ b/backend/app/schemas/LevelTypeSchema.js @@ -1,4 +1,5 @@ const { z } = require('zod') +const LevelSchema = require('./LevelSchema') const LevelTypeSchema = z.object({ id: z.number().int(), @@ -9,6 +10,7 @@ const LevelTypeSchema = z.object({ town: z.number().int(), district: z.number().int(), neighborhood: z.number().int(), + level: LevelSchema.array(), }) module.exports = LevelTypeSchema diff --git a/backend/app/schemas/MediaMetaSchema.js b/backend/app/schemas/MediaMetaSchema.js index 639bb9c6..e8b1d637 100644 --- a/backend/app/schemas/MediaMetaSchema.js +++ b/backend/app/schemas/MediaMetaSchema.js @@ -1,11 +1,15 @@ const { z } = require('zod') +const MediaSchema = require('./MediaSchema') +const MediaTypeSchema = require('./MediaTypeSchema') const MediaMetaSchema = z.object({ id: z.number().int(), path: z.string(), mimeType: z.string(), fileSize: z.string(), + media: MediaSchema, mediaId: z.number().int(), + mediaType: MediaTypeSchema, mediaTypeId: z.number().int(), }) diff --git a/backend/app/schemas/MediaSchema.js b/backend/app/schemas/MediaSchema.js index 4c0a25a5..d4b1cc49 100644 --- a/backend/app/schemas/MediaSchema.js +++ b/backend/app/schemas/MediaSchema.js @@ -1,11 +1,19 @@ const { z } = require('zod') +const UserSchema = require('./UserSchema') +const AdsSchema = require('./AdsSchema') +const MediaMetaSchema = require('./MediaMetaSchema') const MediaSchema = z.object({ id: z.number().int(), path: z.string(), mimeType: z.string(), fileSize: z.string(), + user: UserSchema, userId: z.number().int(), + avatar: UserSchema.optional(), + ad: AdsSchema.optional(), + adId: z.number().int().nullish(), + MediaMeta: MediaMetaSchema.array(), }) module.exports = MediaSchema diff --git a/backend/app/schemas/MediaTypeSchema.js b/backend/app/schemas/MediaTypeSchema.js index fcd5e0db..7b553dc5 100644 --- a/backend/app/schemas/MediaTypeSchema.js +++ b/backend/app/schemas/MediaTypeSchema.js @@ -1,4 +1,5 @@ const { z } = require('zod') +const MediaMetaSchema = require('./MediaMetaSchema') const MediaTypeSchema = z.object({ id: z.number().int(), @@ -7,6 +8,7 @@ const MediaTypeSchema = z.object({ medium: z.boolean(), large: z.boolean(), original: z.boolean(), + mediaMeta: MediaMetaSchema.array(), }) module.exports = MediaTypeSchema diff --git a/backend/app/schemas/MessageSchema.js b/backend/app/schemas/MessageSchema.js index be1d42cc..cb6d9703 100644 --- a/backend/app/schemas/MessageSchema.js +++ b/backend/app/schemas/MessageSchema.js @@ -1,8 +1,12 @@ const { z } = require('zod') +const UserSchema = require('./UserSchema') +const ConversationSchema = require('./ConversationSchema') const MessageSchema = z.object({ id: z.number().int(), + sender: UserSchema, senderId: z.number().int(), + conversation: ConversationSchema, conversationId: z.number().int(), text: z.string(), createdAt: z.date().optional(), diff --git a/backend/app/schemas/RecoverPasswordLogSchema.js b/backend/app/schemas/RecoverPasswordLogSchema.js index b85d4c05..108bb069 100644 --- a/backend/app/schemas/RecoverPasswordLogSchema.js +++ b/backend/app/schemas/RecoverPasswordLogSchema.js @@ -1,9 +1,11 @@ const { z } = require('zod') +const UserSchema = require('./UserSchema') const RecoverPasswordLogSchema = z.object({ id: z.number().int(), createdAt: z.date().optional(), password: z.string(), + user: UserSchema, userId: z.number().int(), }) diff --git a/backend/app/schemas/UserConversationSchema.js b/backend/app/schemas/UserConversationSchema.js index f04c9fee..b529460f 100644 --- a/backend/app/schemas/UserConversationSchema.js +++ b/backend/app/schemas/UserConversationSchema.js @@ -1,8 +1,12 @@ const { z } = require('zod') +const UserSchema = require('./UserSchema') +const ConversationSchema = require('./ConversationSchema') const UserConversationSchema = z.object({ id: z.number().int(), + user: UserSchema, userId: z.number().int(), + conversation: ConversationSchema, conversationId: z.number().int(), }) diff --git a/backend/app/schemas/UserRoleSchema.js b/backend/app/schemas/UserRoleSchema.js index c397f1eb..11aaea43 100644 --- a/backend/app/schemas/UserRoleSchema.js +++ b/backend/app/schemas/UserRoleSchema.js @@ -1,4 +1,5 @@ const { z } = require('zod') +const UserSchema = require('./UserSchema') const UserRoleSchema = z.object({ id: z.number().int(), @@ -7,6 +8,7 @@ const UserRoleSchema = z.object({ developer: z.boolean().optional(), manager: z.boolean().optional(), registered: z.boolean().optional(), + user: UserSchema.array(), }) module.exports = UserRoleSchema diff --git a/backend/app/schemas/UserSchema.js b/backend/app/schemas/UserSchema.js index fa0ce01f..1fe4fc95 100644 --- a/backend/app/schemas/UserSchema.js +++ b/backend/app/schemas/UserSchema.js @@ -1,4 +1,13 @@ const { z } = require('zod') +const UserStatusSchema = require('./UserStatusSchema') +const UserRoleSchema = require('./UserRoleSchema') +const AccesLogSchema = require('./AccesLogSchema') +const RecoverPasswordLogSchema = require('./RecoverPasswordLogSchema') +const MediaSchema = require('./MediaSchema') +const AdsSchema = require('./AdsSchema') +const MessageSchema = require('./MessageSchema') +const UserConversationSchema = require('./UserConversationSchema') +const InvoiceSchema = require('./InvoiceSchema') // Helper schema for Json fields const literalSchema = z.union([z.object().partial(), z.null(), z.undefined()]) @@ -12,10 +21,20 @@ const UserSchema = z.object({ password: z.string(), createdAt: z.date().optional(), updatedAt: z.date(), + userStatus: UserStatusSchema, userStatusId: z.number().int(), + userRole: UserRoleSchema, userRoleId: z.number().int(), + accesLog: AccesLogSchema.array(), + recoverPassword: RecoverPasswordLogSchema.array(), + media: MediaSchema.array(), + ads: AdsSchema.array(), + avatar: MediaSchema.optional(), avatarId: z.number().int().nullish(), developerData: jsonSchema, + messagesSent: MessageSchema.array(), + userConversations: UserConversationSchema.array(), + userInvoices: InvoiceSchema.array(), }) module.exports = UserSchema diff --git a/backend/app/schemas/UserStatusSchema.js b/backend/app/schemas/UserStatusSchema.js index 91bb062b..290900a9 100644 --- a/backend/app/schemas/UserStatusSchema.js +++ b/backend/app/schemas/UserStatusSchema.js @@ -1,4 +1,5 @@ const { z } = require('zod') +const UserSchema = require('./UserSchema') const UserStatusSchema = z.object({ id: z.number().int(), @@ -7,6 +8,7 @@ const UserStatusSchema = z.object({ pending: z.boolean().optional(), suspended: z.boolean().optional(), deleted: z.boolean().optional(), + user: UserSchema.array(), }) module.exports = UserStatusSchema diff --git a/backend/db/schema-db.png b/backend/db/schema-db.png index dad185e3..891ab251 100644 Binary files a/backend/db/schema-db.png and b/backend/db/schema-db.png differ diff --git a/backend/db/schema-db.puml b/backend/db/schema-db.puml index 72ac5c3b..6c48ab59 100644 --- a/backend/db/schema-db.puml +++ b/backend/db/schema-db.puml @@ -76,7 +76,9 @@ entity Media { * user: User * userId: Int avatar: User? - * mediaMeta: MediaMeta[] + ad: Ads? + adId: Int? + * MediaMeta: MediaMeta[] } entity MediaMeta { @@ -164,6 +166,7 @@ entity Ads { * adStatusId: Int * createdAt: DateTime * updatedAt: DateTime + * media: Media[] } entity Conversation { diff --git a/backend/prisma/itaGenerator.js b/backend/prisma/itaGenerator.js index 7837342c..02226ece 100644 --- a/backend/prisma/itaGenerator.js +++ b/backend/prisma/itaGenerator.js @@ -13,51 +13,86 @@ const writeTypeSpecificSchemas = (model) => { return `\n${out}` } -const getZodConstructor = (field, getRelatedModelName = (name) => name.toString()) => { - let zodType = 'z.unknown()' - const extraModifiers = [''] +const getZodConstructor = (field, modelName, getRelatedModelName = (name) => name.toString()) => { + let zodType = 'z.unknown()'; + const extraModifiers = ['']; + if (field.kind === 'scalar') { switch (field.type) { case 'String': - zodType = 'z.string()' - break + zodType = 'z.string()'; + break; case 'Int': - zodType = 'z.number()' - extraModifiers.push('int()') - break + zodType = 'z.number()'; + extraModifiers.push('int()'); + break; case 'BigInt': - zodType = 'z.bigint()' - break + zodType = 'z.bigint()'; + break; case 'DateTime': - zodType = 'z.date()' - break + zodType = 'z.date()'; + break; case 'Float': - zodType = 'z.number()' - break + zodType = 'z.number()'; + break; case 'Decimal': - zodType = 'z.number()' - break + zodType = 'z.number()'; + break; case 'Json': - zodType = `jsonSchema` - break + zodType = `jsonSchema`; + break; case 'Boolean': - zodType = 'z.boolean()' - break + zodType = 'z.boolean()'; + break; default: } } else if (field.kind === 'enum') { - zodType = `z.nativeEnum(${field.type})` - } else if (field.kind === 'object') { - zodType = getRelatedModelName(field.type) + zodType = `z.nativeEnum(${field.type})`; +} else if (field.kind === 'object') { + if (field.type === modelName) { + zodType = `z.lazy(() => ${modelName}Schema)`; + } else { + zodType = getRelatedModelName(field.type); + } + if (!field.isRequired) extraModifiers.push('optional()'); } - if (field.isList) extraModifiers.push('array()') - if (!field.isRequired && field.type !== 'Json') extraModifiers.push('nullish()') - if (field.hasDefaultValue && !field.isId) extraModifiers.push('optional()') + if (field.isList) extraModifiers.push('array()'); + if (!field.isRequired && field.type !== 'Json' && field.kind !== 'object') extraModifiers.push('nullish()'); + if (field.hasDefaultValue && !field.isId) extraModifiers.push('optional()'); + + return `${zodType}${extraModifiers.join('.')}`; +} + +const getRelatedModelImports = (model, models, enums) => { + const relatedModels = new Set() + const relatedEnums = new Set() + model.fields.forEach((field) => { + if (field.kind === 'object' && field.type !== model.name) { + relatedModels.add(field.type) + } else if (field.kind === 'enum') { + relatedEnums.add(field.type) + } + }) + + let imports = '' + relatedModels.forEach((relatedModelName) => { + const schemaName = `${relatedModelName}Schema` + imports += `const ${schemaName} = require('./${schemaName}')\n` + }) + + if (relatedEnums.size > 0) { + imports += `const { `; + relatedEnums.forEach((relatedEnumName, index) => { + imports += `${relatedEnumName}${index < relatedEnums.size - 1 ? ', ' : ''}`; + }); + imports += ` } = require('@prisma/client')\n`; + } - return `${zodType}${extraModifiers.join('.')}` + return imports } + generatorHelper.generatorHandler({ onManifest() { return { @@ -65,28 +100,25 @@ generatorHelper.generatorHandler({ defaultOutput: '../app/schemas', } }, + onGenerate(options) { - const outputDir = options.generator.output.value - const { models } = options.dmmf.datamodel + const outputDir = options.generator.output.value; + const { models, enums } = options.dmmf.datamodel; models.forEach((m) => { - const zodSchemaName = `${m.name}Schema` - let output = '' - output += `const { z } = require('zod')\n` - output += writeTypeSpecificSchemas(m) - output += `const ${zodSchemaName} = z.object({\n` + const zodSchemaName = `${m.name}Schema`; + let output = ''; + output += `const { z } = require('zod')\n`; + output += getRelatedModelImports(m, models, enums); + output += writeTypeSpecificSchemas(m); + output += `const ${zodSchemaName} = z.object({\n`; m.fields.forEach((f) => { - if (f.kind === 'scalar') { - output += ` ${f.name}: ${getZodConstructor(f)},\n` - } - }) - output += `})\n\n` - output += `module.exports = ${zodSchemaName}\n` - try { - fs.writeFileSync(`${outputDir}/${zodSchemaName}.js`, output) - console.log(`Generated ${zodSchemaName}.js`) - } catch (error) { - throw new Error(error) - } - }) + output += ` ${f.name}: ${getZodConstructor(f, m.name, (name) => `${name}Schema`)},\n`; + }); + output += `})\n\n`; + output += `module.exports = ${zodSchemaName}\n`; + + const outputPath = `${outputDir}/${zodSchemaName}.js`; + fs.writeFileSync(outputPath, output); + }); }, }) diff --git a/backend/prisma/migrations/20230316105946_backend/migration 2.sql b/backend/prisma/migrations/20230316105946_backend/migration 2.sql new file mode 100644 index 00000000..0159f947 --- /dev/null +++ b/backend/prisma/migrations/20230316105946_backend/migration 2.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "media" ADD COLUMN "adId" INTEGER; + +-- AddForeignKey +ALTER TABLE "media" ADD CONSTRAINT "media_adId_fkey" FOREIGN KEY ("adId") REFERENCES "ads"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/backend/prisma/migrations/20230316105946_backend/migration.sql b/backend/prisma/migrations/20230316105946_backend/migration.sql new file mode 100644 index 00000000..0159f947 --- /dev/null +++ b/backend/prisma/migrations/20230316105946_backend/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "media" ADD COLUMN "adId" INTEGER; + +-- AddForeignKey +ALTER TABLE "media" ADD CONSTRAINT "media_adId_fkey" FOREIGN KEY ("adId") REFERENCES "ads"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 5356c78e..7bd30d7e 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -1,252 +1,255 @@ datasource db { - provider = "postgresql" - url = env("DATABASE_URL") + provider = "postgresql" + url = env("DATABASE_URL") } generator itaGenerator { - provider = "node ./prisma/itaGenerator.js" + provider = "node /Users/ivanlegranbizarro/Documents/ita-directory/backend/prisma/itaGenerator.js" // Por qué no funciona con el path relativo? } generator client { - provider = "prisma-client-js" - binaryTargets = ["native", "linux-musl"] + provider = "prisma-client-js" + binaryTargets = ["native", "linux-musl"] } model UserRole { - id Int @id @default(autoincrement()) - name String - admin Boolean @default(false) - developer Boolean @default(false) //Developer role added - manager Boolean @default(false) - registered Boolean @default(false) - user User[] + id Int @id @default(autoincrement()) + name String + admin Boolean @default(false) + developer Boolean @default(false) // Developer role added + manager Boolean @default(false) + registered Boolean @default(false) + user User[] - @@map("user_role") + @@map("user_role") } model UserStatus { - id Int @id @default(autoincrement()) - name String - active Boolean @default(false) - pending Boolean @default(false) - suspended Boolean @default(false) - deleted Boolean @default(false) - user User[] + id Int @id @default(autoincrement()) + name String + active Boolean @default(false) + pending Boolean @default(false) + suspended Boolean @default(false) + deleted Boolean @default(false) + user User[] - @@map("user_status") + @@map("user_status") } model User { - id Int @id @default(autoincrement()) - name String? - lastnames String? - email String @unique - password String - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - userStatus UserStatus @relation(fields: [userStatusId], references: [id]) - userStatusId Int @map("user_status_id") - userRole UserRole @relation(fields: [userRoleId], references: [id]) - userRoleId Int @map("user_role_id") - accesLog AccesLog[] - recoverPassword RecoverPasswordLog[] - media Media[] - ads Ads[] - avatar Media? @relation("avatar", fields: [avatarId], references: [id]) - avatarId Int? @unique - developerData Json? @map("developer_data") //Added developer data (not a jsonb?) - messagesSent Message[] @relation("sender") - userConversations UserConversation[] @relation("conv_user") - userInvoices Invoice[] - - @@map("user") + id Int @id @default(autoincrement()) + name String? + lastnames String? + email String @unique + password String + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + userStatus UserStatus @relation(fields: [userStatusId], references: [id]) + userStatusId Int @map("user_status_id") + userRole UserRole @relation(fields: [userRoleId], references: [id]) + userRoleId Int @map("user_role_id") + accesLog AccesLog[] + recoverPassword RecoverPasswordLog[] + media Media[] + ads Ads[] + avatar Media? @relation("avatar", fields: [avatarId], references: [id]) + avatarId Int? @unique + developerData Json? @map("developer_data") // Added developer data (not a jsonb?) + messagesSent Message[] @relation("sender") + userConversations UserConversation[] @relation("conv_user") + userInvoices Invoice[] + + @@map("user") } model AccesLog { - id Int @id @default(autoincrement()) - login DateTime - logout DateTime - user User @relation(fields: [userId], references: [id]) - userId Int @map("user_id") + id Int @id @default(autoincrement()) + login DateTime + logout DateTime + user User @relation(fields: [userId], references: [id]) + userId Int @map("user_id") - @@map("acces_log") + @@map("acces_log") } model RecoverPasswordLog { - id Int @id @default(autoincrement()) - createdAt DateTime @default(now()) @map("created_at") - password String - user User @relation(fields: [userId], references: [id]) - userId Int @map("user_id") + id Int @id @default(autoincrement()) + createdAt DateTime @default(now()) @map("created_at") + password String + user User @relation(fields: [userId], references: [id]) + userId Int @map("user_id") - @@map("recover_password_log") + @@map("recover_password_log") } model Media { - id Int @id @default(autoincrement()) - path String - mimeType String @map("mime_type") - fileSize String @map("file_size") - user User @relation(fields: [userId], references: [id]) - userId Int @map("user_id") - avatar User? @relation("avatar") - mediaMeta MediaMeta[] + id Int @id @default(autoincrement()) + path String + mimeType String @map("mime_type") + fileSize String @map("file_size") + user User @relation(fields: [userId], references: [id]) + userId Int @map("user_id") + avatar User? @relation("avatar") + ad Ads? @relation(fields: [adId], references: [id]) + adId Int? + MediaMeta MediaMeta[] - @@map("media") + @@map("media") } model MediaMeta { - id Int @id @default(autoincrement()) - path String - mimeType String @map("mime_type") - fileSize String @map("file_size") - media Media @relation(fields: [mediaId], references: [id]) - mediaId Int @map("media_id") - mediaType MediaType @relation(fields: [mediaTypeId], references: [id]) - mediaTypeId Int @map("media_type_id") + id Int @id @default(autoincrement()) + path String + mimeType String @map("mime_type") + fileSize String @map("file_size") + media Media @relation(fields: [mediaId], references: [id]) + mediaId Int @map("media_id") + mediaType MediaType @relation(fields: [mediaTypeId], references: [id]) + mediaTypeId Int @map("media_type_id") - @@map("media_meta") + @@map("media_meta") } model MediaType { - id Int @id @default(autoincrement()) - name String - thumnail Boolean - medium Boolean - large Boolean - original Boolean - mediaMeta MediaMeta[] // @map("media_meta") + id Int @id @default(autoincrement()) + name String + thumnail Boolean + medium Boolean + large Boolean + original Boolean + mediaMeta MediaMeta[] // @map("media_meta") - @@map("media_type") + @@map("media_type") } model LevelType { - id Int @id @default(autoincrement()) - name String - country Int // País - state Int // Autonomía - city Int // Provincia - town Int // Ciudad-Población - district Int // Distrito - neighborhood Int // Barrio - level Level[] + id Int @id @default(autoincrement()) + name String + country Int // País + state Int // Autonomía + city Int // Provincia + town Int // Ciudad-Población + district Int // Distrito + neighborhood Int // Barrio + level Level[] - @@map("level_type") + @@map("level_type") } model Level { - id Int @id @default(autoincrement()) - name String - parent Level? @relation("parent", fields: [parentId], references: [id]) - parentId Int? @map("parent_id") - child Level[] @relation("parent") - levelType LevelType @relation(fields: [levelTypeId], references: [id]) - levelTypeId Int @map("level_type_id") + id Int @id @default(autoincrement()) + name String + parent Level? @relation("parent", fields: [parentId], references: [id]) + parentId Int? @map("parent_id") + child Level[] @relation("parent") + levelType LevelType @relation(fields: [levelTypeId], references: [id]) + levelTypeId Int @map("level_type_id") - @@map("level") + @@map("level") } model AdType { - id Int @id @default(autoincrement()) - name String - house Int - room Int - garage Int - storage Int - office Int - warehouse Int - building Int - newBuilding Int @map("new_building") - ads Ads[] + id Int @id @default(autoincrement()) + name String + house Int + room Int + garage Int + storage Int + office Int + warehouse Int + building Int + newBuilding Int @map("new_building") + ads Ads[] - @@map("ad_type") + @@map("ad_type") } model AdStatus { - id Int @id @default(autoincrement()) - name String - unPublish Int @map("un_publish") - publish Int - ads Ads[] + id Int @id @default(autoincrement()) + name String + unPublish Int @map("un_publish") + publish Int + ads Ads[] - @@map("ad_status") + @@map("ad_status") } model Ads { - id Int @id @default(autoincrement()) - user User @relation(fields: [userId], references: [id]) - userId Int @map("user_id") - title String - description String - nRooms Int @map("n_rooms") - price Int - includedExpenses Boolean @default(false) @map("included_expenses") - squareMeters Int @map("square_meters") - nBathrooms Int @map("n_bathrooms") - city String - mapLat Decimal @map("map_lat") - mapLon Decimal @map("map_lon") - adType AdType @relation(fields: [adTypeId], references: [id]) - adTypeId Int @map("ad_type_id") - adStatus AdStatus @relation(fields: [adStatusId], references: [id]) - adStatusId Int @map("ad_status_id") - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - - @@map("ads") + id Int @id @default(autoincrement()) + user User @relation(fields: [userId], references: [id]) + userId Int @map("user_id") + title String + description String + nRooms Int @map("n_rooms") + price Int + includedExpenses Boolean @default(false) @map("included_expenses") + squareMeters Int @map("square_meters") + nBathrooms Int @map("n_bathrooms") + city String + mapLat Decimal @map("map_lat") + mapLon Decimal @map("map_lon") + adType AdType @relation(fields: [adTypeId], references: [id]) + adTypeId Int @map("ad_type_id") + adStatus AdStatus @relation(fields: [adStatusId], references: [id]) + adStatusId Int @map("ad_status_id") + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + media Media[] + + @@map("ads") } model Conversation { - id Int @id @default(autoincrement()) - messages Message[] @relation("conv") - participants UserConversation[] @relation("user_conv") + id Int @id @default(autoincrement()) + messages Message[] @relation("conv") + participants UserConversation[] @relation("user_conv") - @@map("conversation") + @@map("conversation") } model UserConversation { - id Int @id @default(autoincrement()) - user User @relation("conv_user", fields: [userId], references: [id]) - userId Int @map("user_id") - conversation Conversation @relation("user_conv", fields: [conversationId], references: [id]) - conversationId Int @map("conversation_id") + id Int @id @default(autoincrement()) + user User @relation("conv_user", fields: [userId], references: [id]) + userId Int @map("user_id") + conversation Conversation @relation("user_conv", fields: [conversationId], references: [id]) + conversationId Int @map("conversation_id") - @@map("user_conversation") + @@map("user_conversation") } model Message { - id Int @id @default(autoincrement()) - sender User @relation("sender", fields: [senderId], references: [id]) - senderId Int @map("sender_id") - conversation Conversation @relation("conv", fields: [conversationId], references: [id]) - conversationId Int @map("conversation_id") - text String - createdAt DateTime @default(now()) @map("created_at") + id Int @id @default(autoincrement()) + sender User @relation("sender", fields: [senderId], references: [id]) + senderId Int @map("sender_id") + conversation Conversation @relation("conv", fields: [conversationId], references: [id]) + conversationId Int @map("conversation_id") + text String + createdAt DateTime @default(now()) @map("created_at") - @@map("message") + @@map("message") } model Invoice { - id Int @id @default(autoincrement()) - user User @relation(fields: [userId], references: [id]) - userId Int @map("user_id") - billingAddress String? @map("billing_address") - postalCode String? @map("postal_code") - city String - state String - country String - vatId String @map("vat_id") - vatAmount Int @map("vat_amount") - secondTax Int @map("second_tax") - createdAt DateTime @default(now()) @map("created_at") - invoiceNumber String @unique @map("invoice_number") - status Status @default(PENDING) - - @@map("invoice") + id Int @id @default(autoincrement()) + user User @relation(fields: [userId], references: [id]) + userId Int @map("user_id") + billingAddress String? @map("billing_address") + postalCode String? @map("postal_code") + city String + state String + country String + vatId String @map("vat_id") + vatAmount Int @map("vat_amount") + secondTax Int @map("second_tax") + createdAt DateTime @default(now()) @map("created_at") + invoiceNumber String @unique @map("invoice_number") + status Status @default(PENDING) + + @@map("invoice") } enum Status { - PAID - PENDING - CANCELLED -} \ No newline at end of file + PAID + PENDING + CANCELLED +}