diff --git a/src/models/profile.model.ts b/src/models/profile.model.ts index 27117af..a0fffba 100644 --- a/src/models/profile.model.ts +++ b/src/models/profile.model.ts @@ -1,12 +1,29 @@ import mongoose from 'mongoose' -import type { ProfileSchema } from '../types/profiles' +const Schema = mongoose.Schema +import type { DigimonSchema, TechniqueSchema } from '../types/digimon' const techniqueSchema = new mongoose.Schema({ name: { type: String, required: true }, - description: { type: String, required: true } + description: { type: String, required: true }, + timestamps: { + createdAt: { + type: Date, + required: true, + default: Date.now() + }, + updatedAt: { + type: Date, + default: null + }, + deletedAt: { + type: Date, + default: null + } + } }) -const profileSchema = new mongoose.Schema({ +const digimonSchema = new mongoose.Schema({ + _id: Schema.Types.ObjectId, name: { type: String, unique: true, @@ -36,7 +53,7 @@ const profileSchema = new mongoose.Schema({ type: Array, required: true }, - technique: [techniqueSchema], + technique: [{ type: Schema.Types.ObjectId, ref: 'technique' }], artwork: { type: String, required: true, @@ -53,7 +70,8 @@ const profileSchema = new mongoose.Schema({ default: Date.now() }, updatedAt: { - type: Date + type: Date, + default: null }, deletedAt: { type: Date, @@ -62,7 +80,12 @@ const profileSchema = new mongoose.Schema({ } }) -export default mongoose.model( - 'profile', - profileSchema +const Digimon = mongoose.model( + 'digimon', + digimonSchema +) + +const Technique = mongoose.model( + 'technique', + techniqueSchema ) diff --git a/src/repositories/profile.repository.ts b/src/repositories/profile.repository.ts index b4cb21f..6891aff 100644 --- a/src/repositories/profile.repository.ts +++ b/src/repositories/profile.repository.ts @@ -7,8 +7,8 @@ import type { Attribute, Field, Group, - ProfileSchema -} from '../types/profiles' + DigimonSchema +} from '../types/digimon' class ProfileRepository { async read(req: Request) { @@ -85,7 +85,7 @@ class ProfileRepository { technique: getRequestBody.technique ?? getDocumentFromDB[0].technique, artwork: getRequestBody.artwork ?? getDocumentFromDB[0].artwork, profile: getRequestBody.profile ?? getDocumentFromDB[0].profile - } as ProfileSchema + } as DigimonSchema const updateProfile = await profileModel.updateOne( { diff --git a/src/types/profiles.ts b/src/types/digimon.ts similarity index 89% rename from src/types/profiles.ts rename to src/types/digimon.ts index 50cc998..3ccf515 100644 --- a/src/types/profiles.ts +++ b/src/types/digimon.ts @@ -1,16 +1,27 @@ -export interface Profile { +export interface Digimon { name: string level: Level type: Type attribute: Attribute field: Field[] | null group: Group[] | null - technique: [{ name: string; description: string | null }] - artwork: string - profile: string + technique: [Technique] + profile: { + artwork: string + sprite: { + sprite: string[] + map: string + } + description: string + } +} + +export type Technique = { + name: string + description: string | null } -export interface ProfileSchema extends Profile { +export interface DigimonSchema extends Digimon { _id: { $oid: string } __v: number timestamps: { @@ -20,6 +31,15 @@ export interface ProfileSchema extends Profile { } } +export interface TechniqueSchema extends Technique { + _id: { $oid: string } + timestamps: { + createdAt: string + updatedAt?: string + deletedAt: string + } +} + export type Level = | 'Baby I' | 'Baby II'