Skip to content

Commit

Permalink
Feature : Mongoose 스키마 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
hye-on committed Jun 26, 2024
1 parent dc2cec7 commit dc32c76
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/schema/folder.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument, Schema as MongooseSchema } from 'mongoose';
import { FolderType } from '../types/folder-type.enum';

@Schema({ collection: 'folders', timestamps: true, versionKey: false })
export class Folder {
@Prop({ required: true })
userId: string;

@Prop({ required: true })
name: string;

@Prop({ required: true, enum: FolderType })
type: FolderType;
}

export type FolderDocument = HydratedDocument<Folder>;
export const FolderSchema = SchemaFactory.createForClass(Folder);
4 changes: 4 additions & 0 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from './user.schema';
export * from './folder.schema';
export * from './keyword.schema';
export * from './post.schema';
export * from './postAIClassification.schema';
11 changes: 11 additions & 0 deletions src/schema/keyword.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

@Schema({ collection: 'keywords', versionKey: false })
export class Keyword {
@Prop({ required: true })
name: string;
}

export type KeywordDocument = Keyword & Document;
export const KeywordSchema = SchemaFactory.createForClass(Keyword);
33 changes: 33 additions & 0 deletions src/schema/post.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument, Schema as MongooseSchema } from 'mongoose';

@Schema({ collection: 'posts', timestamps: true, versionKey: false })
export class Post {
@Prop({ required: true })
userId: string;

@Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Folder' })
folderId: MongooseSchema.Types.ObjectId;

@Prop({ required: true })
url: string;

@Prop({ required: true })
title!: string;

@Prop({ required: true })
description!: string;

@Prop({ default: false })
isFavorite: boolean;

@Prop({
required: false,
type: MongooseSchema.Types.ObjectId,
ref: 'PostAIClassification',
})
aiClassificationId?: MongooseSchema.Types.ObjectId;
}

export type PostDocument = HydratedDocument<Post>;
export const PostSchema = SchemaFactory.createForClass(Post);
33 changes: 33 additions & 0 deletions src/schema/postAIClassification.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument, Schema as MongooseSchema } from 'mongoose';
import { Keyword, KeywordSchema } from './keyword.schema';

@Schema({
collection: 'post_ai_classification',
timestamps: true,
versionKey: false,
})
export class PostAIClassification {
@Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Folder' })
suggestedFolderId: MongooseSchema.Types.ObjectId;

@Prop({ required: true })
url: string;

@Prop({ required: true })
description: string;

@Prop({ required: true, type: KeywordSchema })
keywords: Keyword[];

@Prop({ type: Date })
completedAt: Date;

@Prop({ type: Date })
deletedAt: Date;
}

export type PostAIClassificationDocument =
HydratedDocument<PostAIClassification>;
export const PostAIClassificationSchema =
SchemaFactory.createForClass(PostAIClassification);
14 changes: 14 additions & 0 deletions src/schema/postKeyword.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument, Schema as MongooseSchema } from 'mongoose';

@Schema({ collection: 'post_keywords', versionKey: false })
export class PostKeyword {
@Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Post' })
postId: MongooseSchema.Types.ObjectId;

@Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Keyword' })
keywordId: MongooseSchema.Types.ObjectId;
}

export type PostKeywordDocument = HydratedDocument<PostKeyword>;
export const PostKeywordSchema = SchemaFactory.createForClass(PostKeyword);
4 changes: 4 additions & 0 deletions src/types/folder-type.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum FolderType {
CUSTOM = 'Custom',
DEFAULT = 'Default',
}

0 comments on commit dc32c76

Please sign in to comment.