-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsong.entity.ts
More file actions
106 lines (76 loc) · 2.98 KB
/
song.entity.ts
File metadata and controls
106 lines (76 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { SongStats } from '@shared/validation/song/dto/SongStats';
import { SongViewUploader } from '@shared/validation/song/dto/SongView.dto';
import { ThumbnailData } from '@shared/validation/song/dto/ThumbnailData.dto';
import type {
CategoryType,
LicenseType,
VisibilityType,
} from '@shared/validation/song/dto/types';
import { HydratedDocument, Schema as MongooseSchema, Types } from 'mongoose';
import { User } from '@server/user/entity/user.entity';
@Schema({
timestamps: true,
versionKey: false,
toJSON: {
virtuals: true,
transform: (doc, ret) => {
delete ret._id;
},
},
})
export class Song {
@Prop({ type: String, required: true, unique: true })
publicId: string;
@Prop({ type: MongooseSchema.Types.Date, required: true, default: Date.now })
createdAt: Date; // Added automatically by Mongoose: https://mongoosejs.com/docs/timestamps.html
@Prop({ type: MongooseSchema.Types.Date, required: true, default: Date.now })
updatedAt: Date; // Added automatically by Mongoose: https://mongoosejs.com/docs/timestamps.html
@Prop({ type: MongooseSchema.Types.ObjectId, required: true, ref: 'User' })
uploader: Types.ObjectId | User; // Populated with the uploader's user document
@Prop({ type: String, required: true })
thumbnailUrl: string;
@Prop({ type: String, required: true })
nbsFileUrl: string;
@Prop({ type: String, required: true })
packedSongUrl: string;
// SONG DOCUMENT ATTRIBUTES
@Prop({ type: Number, required: true, default: 0 })
playCount: number;
@Prop({ type: Number, required: true, default: 0 })
downloadCount: number;
@Prop({ type: Number, required: true, default: 0 })
likeCount: number;
// SONG FILE ATTRIBUTES (Populated from upload form - updatable)
@Prop({ type: ThumbnailData, required: true })
thumbnailData: ThumbnailData;
@Prop({ type: String, required: true, index: true })
category: CategoryType;
@Prop({ type: String, required: true })
visibility: VisibilityType;
@Prop({ type: String, required: true })
license: LicenseType;
@Prop({ type: Array<string>, required: true })
customInstruments: string[];
@Prop({ type: Boolean, required: true, default: true })
allowDownload: boolean;
@Prop({ type: String, required: true, index: true })
title: string;
@Prop({ type: String, required: false, index: true })
originalAuthor: string;
@Prop({ type: String, required: false, index: true })
description: string;
// SONG FILE ATTRIBUTES (Populated from NBS file - immutable)
@Prop({ type: Number, required: true })
fileSize: number;
@Prop({ type: SongStats, required: true })
stats: SongStats;
// EXTERNAL ATTRIBUTES
@Prop({ type: String, required: false })
webhookMessageId?: string | null;
}
export const SongSchema = SchemaFactory.createForClass(Song);
export type SongDocument = Song & HydratedDocument<Song>;
export type SongWithUser = Omit<Song, 'uploader'> & {
uploader: SongViewUploader;
};