universo-platform-3d
80 строк · 2.0 Кб
1import * as mongoose from 'mongoose'
2import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
3import { ApiProperty } from '@nestjs/swagger'
4import { BLOCK_TYPE } from '../option-sets/block-type'
5import { User } from '../user/user.schema'
6
7export class BlockPublicData {
8@ApiProperty() // @ApiProperty must be included to be exposed by the API and flow to FE codegen
9_id = '' // Must not be undefined
10@ApiProperty()
11createdAt = new Date()
12@ApiProperty()
13updatedAt = new Date()
14@ApiProperty()
15name = ''
16@ApiProperty()
17description = ''
18@ApiProperty({ enum: BLOCK_TYPE })
19blockType = ''
20}
21
22export type BlockDocument = Block & Document
23
24@Schema({
25timestamps: true,
26toJSON: {
27virtuals: true
28},
29strict: false // TEMP allowed until we lock down the structure for game logic
30})
31export class Block {
32/**
33* @description Human-readable name that the user will see for this block. The maxlength is arbitrary.
34* @date 2022-12-13 16:46
35*/
36@Prop({ required: true, maxlength: 255 })
37@ApiProperty()
38name: string
39
40@Prop({
41required: false,
42default: BLOCK_TYPE.GENERIC,
43type: String,
44enum: BLOCK_TYPE
45})
46@ApiProperty({ enum: BLOCK_TYPE })
47blockType: string
48
49/**
50* @description Human-readable name that the user will see for this block. The maxlength is arbitrary.
51* @date 2022-12-13 16:46
52*/
53@Prop()
54@ApiProperty({ required: false, maxLength: 1000 })
55description: string
56
57/**
58* @description Who the block was created by. This will be a TM account if is true
59* @date 2022-12-13 16:46
60*/
61@Prop({
62type: mongoose.Schema.Types.ObjectId,
63ref: 'User'
64})
65@ApiProperty()
66creator: User
67
68/**
69* @description Whether the block is available to the public for all to use. This should be for general Mirror-provided blocks
70* @date 2022-12-13 16:45
71*/
72@Prop({
73required: true,
74default: false
75})
76@ApiProperty()
77mirrorPublicLibrary: boolean
78}
79
80export const BlockSchema = SchemaFactory.createForClass(Block)
81