universo-platform-3d
63 строки · 1.8 Кб
1import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2import { ApiProperty } from '@nestjs/swagger'
3import mongoose, { Document } from 'mongoose'
4import { Role, RoleSchema } from '../roles/models/role.schema'
5import { ISchemaWithRole } from '../roles/role-consumer.interface'
6import { AssetPublicData } from './asset.schema'
7
8// Properties must not be undefined so that getPublicPropertiesForMongooseQuery can work
9export class TexturePublicData extends AssetPublicData {
10@ApiProperty()
11textureName = ''
12@ApiProperty()
13textureImageFileHashMD5 = ''
14@ApiProperty()
15textureLowQualityFileHashMD5 = ''
16@ApiProperty()
17textureImagePropertyAppliesTo = ''
18}
19
20export type TextureDocument = Texture & Document
21
22@Schema({
23timestamps: true,
24toJSON: {
25virtuals: true
26}
27// discriminatorKey: __t <- don't uncomment this line: this line is to note that __t is the Mongoose default discriminator key that we use for simplicity rather than specifying our own discriminator key. When this schema is instantiated, __t is "Texture". This is DIFFERENT from assetType since we hadn't been using discriminators up until 2023-02-04 18:49:52. See https://mongoosejs.com/docs/discriminators.html#discriminator-keys. Walkthrough: https://www.loom.com/share/7e09d2777ef94368bcd5fd8c8341b5ef
28})
29export class Texture {
30_id: string
31@Prop({
32trim: true
33})
34@ApiProperty()
35textureImageFileHashMD5: string
36
37@Prop({
38trim: true
39})
40@ApiProperty()
41textureLowQualityFileHashMD5: string
42
43@Prop({
44trim: true
45})
46@ApiProperty()
47textureImagePropertyAppliesTo: string
48
49/**
50* START Section: ISchemaWithRole implementer
51*/
52@Prop({
53required: true,
54type: RoleSchema
55})
56@ApiProperty()
57role: Role
58/**
59* END Section: ISchemaWithRole implementer
60*/
61}
62
63export const TextureSchema = SchemaFactory.createForClass(Texture)
64