Skip to content
This repository was archived by the owner on Apr 1, 2023. It is now read-only.
Draft
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
39 changes: 31 additions & 8 deletions src/models/profile.model.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -53,7 +70,8 @@ const profileSchema = new mongoose.Schema({
default: Date.now()
},
updatedAt: {
type: Date
type: Date,
default: null
},
deletedAt: {
type: Date,
Expand All @@ -62,7 +80,12 @@ const profileSchema = new mongoose.Schema({
}
})

export default mongoose.model<ProfileSchema & mongoose.Document>(
'profile',
profileSchema
const Digimon = mongoose.model<DigimonSchema & mongoose.Document>(
'digimon',
digimonSchema
)

const Technique = mongoose.model<TechniqueSchema & mongoose.Document>(
'technique',
techniqueSchema
)
6 changes: 3 additions & 3 deletions src/repositories/profile.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type {
Attribute,
Field,
Group,
ProfileSchema
} from '../types/profiles'
DigimonSchema
} from '../types/digimon'

class ProfileRepository {
async read(req: Request) {
Expand Down Expand Up @@ -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(
{
Expand Down
30 changes: 25 additions & 5 deletions src/types/profiles.ts → src/types/digimon.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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'
Expand Down