universo-platform-3d
110 строк · 2.8 Кб
1import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2import { ApiProperty } from '@nestjs/swagger'
3import * as mongoose from 'mongoose'
4import { Document } from 'mongoose'
5import { Role, RoleSchema } from '../roles/models/role.schema'
6import { ISchemaWithRole } from '../roles/role-consumer.interface'
7import { AssetPublicData } from './asset.schema'
8import { Texture } from './texture.schema'
9
10// Properties must not be undefined so that getPublicPropertiesForMongooseQuery can work
11export class MaterialPublicData extends AssetPublicData {
12@ApiProperty({
13example: 'Concrete_super_shiny_example'
14})
15materialName = ''
16@ApiProperty()
17materialTransparencyMode = ''
18@ApiProperty()
19materialTransparencyProperties = ''
20@ApiProperty()
21textures = []
22@ApiProperty()
23externalAssetIds = []
24@ApiProperty()
25parameters = {}
26@ApiProperty()
27materialType = ''
28}
29
30export type MaterialDocument = Material & Document
31
32@Schema({
33timestamps: true,
34toJSON: {
35virtuals: true
36}
37// 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 "Material". 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
38})
39export class Material {
40_id: string
41@Prop({
42trim: true
43})
44@ApiProperty({
45example: 'Concrete_super_shiny_example'
46})
47materialName: string
48
49/**
50* @deprecated This is now a custom setting dependant on material type
51* @date 2023-09-29
52*/
53@Prop({
54trim: true
55})
56@ApiProperty()
57materialTransparencyMode: string
58
59/**
60* @deprecated This is now a custom setting dependant on material type
61* @date 2023-09-29
62*/
63@Prop({
64trim: true
65})
66@ApiProperty()
67materialTransparencyProperties: string
68
69/**
70* @deprecated This information is contained in external_asset_ids
71* @date 2023-09-29
72*/
73@Prop({ type: [mongoose.Schema.Types.ObjectId], ref: 'Texture' })
74@ApiProperty()
75textures: Texture[]
76
77@Prop({ type: [mongoose.Schema.Types.ObjectId], ref: 'Texture' })
78@ApiProperty()
79externalAssetIds: Texture[]
80
81@Prop({ type: mongoose.Schema.Types.Map })
82@ApiProperty()
83parameters: any
84
85@Prop({
86required: false,
87trim: true
88})
89@ApiProperty()
90materialType: string
91
92@Prop()
93@ApiProperty()
94code: string
95
96/**
97* START Section: ISchemaWithRole implementer
98*/
99@Prop({
100required: true,
101type: RoleSchema
102})
103@ApiProperty()
104role: Role
105/**
106* END Section: ISchemaWithRole implementer
107*/
108}
109
110export const MaterialSchema = SchemaFactory.createForClass(Material)
111