Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

697 add 1n relation between ads and media #914

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/app/schemas/AccesLogSchema.js
Original file line number Diff line number Diff line change
@@ -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(),
})

Expand Down
2 changes: 2 additions & 0 deletions backend/app/schemas/AdStatusSchema.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions backend/app/schemas/AdTypeSchema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { z } = require('zod')
const AdsSchema = require('./AdsSchema')

const AdTypeSchema = z.object({
id: z.number().int(),
Expand All @@ -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
8 changes: 8 additions & 0 deletions backend/app/schemas/AdsSchema.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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
4 changes: 4 additions & 0 deletions backend/app/schemas/ConversationSchema.js
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions backend/app/schemas/InvoiceSchema.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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
4 changes: 4 additions & 0 deletions backend/app/schemas/LevelSchema.js
Original file line number Diff line number Diff line change
@@ -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(),
})

Expand Down
2 changes: 2 additions & 0 deletions backend/app/schemas/LevelTypeSchema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { z } = require('zod')
const LevelSchema = require('./LevelSchema')

const LevelTypeSchema = z.object({
id: z.number().int(),
Expand All @@ -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
4 changes: 4 additions & 0 deletions backend/app/schemas/MediaMetaSchema.js
Original file line number Diff line number Diff line change
@@ -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(),
})

Expand Down
8 changes: 8 additions & 0 deletions backend/app/schemas/MediaSchema.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions backend/app/schemas/MediaTypeSchema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { z } = require('zod')
const MediaMetaSchema = require('./MediaMetaSchema')

const MediaTypeSchema = z.object({
id: z.number().int(),
Expand All @@ -7,6 +8,7 @@ const MediaTypeSchema = z.object({
medium: z.boolean(),
large: z.boolean(),
original: z.boolean(),
mediaMeta: MediaMetaSchema.array(),
})

module.exports = MediaTypeSchema
4 changes: 4 additions & 0 deletions backend/app/schemas/MessageSchema.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions backend/app/schemas/RecoverPasswordLogSchema.js
Original file line number Diff line number Diff line change
@@ -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(),
})

Expand Down
4 changes: 4 additions & 0 deletions backend/app/schemas/UserConversationSchema.js
Original file line number Diff line number Diff line change
@@ -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(),
})

Expand Down
2 changes: 2 additions & 0 deletions backend/app/schemas/UserRoleSchema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { z } = require('zod')
const UserSchema = require('./UserSchema')

const UserRoleSchema = z.object({
id: z.number().int(),
Expand All @@ -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
19 changes: 19 additions & 0 deletions backend/app/schemas/UserSchema.js
Original file line number Diff line number Diff line change
@@ -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()])
Expand All @@ -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
2 changes: 2 additions & 0 deletions backend/app/schemas/UserStatusSchema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { z } = require('zod')
const UserSchema = require('./UserSchema')

const UserStatusSchema = z.object({
id: z.number().int(),
Expand All @@ -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
Binary file modified backend/db/schema-db.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion backend/db/schema-db.puml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ entity Media {
* user: User
* userId: Int
avatar: User?
* mediaMeta: MediaMeta[]
ad: Ads?
adId: Int?
* MediaMeta: MediaMeta[]
}

entity MediaMeta {
Expand Down Expand Up @@ -164,6 +166,7 @@ entity Ads {
* adStatusId: Int
* createdAt: DateTime
* updatedAt: DateTime
* media: Media[]
}

entity Conversation {
Expand Down
Loading