Skip to content

Commit 296b851

Browse files
author
Chahat Gupta
committed
Added root constant
1 parent ad8eff2 commit 296b851

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

src/helper/mock_folder.helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class MockFolderHelper {
77
static toJson(model: MockFolderModel, folders: MockFolderModel[] | null = null, files: MockModel[] | null = null) : any {
88
return {
99
id: model._id,
10+
parentId: model.parentId,
1011
name: model.name,
1112
folders: folders?.map((e) => MockFolderHelper.toJson(e)),
1213
files: files?.map((e) => MockHelper.toJson(e))

src/models/mock.model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Schema, Model, model } from 'mongoose'
2+
import Constants from "../common/constants";
23

34
export type MockModel = {
45
_id: string
@@ -12,7 +13,7 @@ const MockSchema: Schema<MockModel> = new Schema<MockModel>({
1213
parentId: {
1314
type: String,
1415
required: false,
15-
default: null
16+
default: Constants.rootPath
1617
},
1718
name: {
1819
type: String,

src/models/mock_folder.model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Schema, Model, model } from 'mongoose'
2+
import Constants from "../common/constants";
23

34
export type MockFolderModel = {
45
_id: string
@@ -11,7 +12,7 @@ const MockFolderSchema: Schema<MockFolderModel> = new Schema<MockFolderModel>({
1112
parentId: {
1213
type: String,
1314
required: false,
14-
default: null
15+
default: Constants.rootPath
1516
},
1617
name: {
1718
type: String,

src/routes/mock_folder.routes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ import { ApiResponse } from '../common/api_response'
44
import mongoose, {Types} from 'mongoose'
55
import {Mock, MockModel} from "../models/mock.model";
66
import MockFolderHelper from "../helper/mock_folder.helper";
7+
import Constants from "../common/constants";
78

89
const router = express.Router()
910

1011
router.get('/', async (req: Request, res: Response): Promise<void> => {
1112
try {
1213
const root: MockFolderModel = {
13-
_id: 'root',
14+
_id: Constants.rootPath,
1415
parentId: null,
1516
name: 'Root'
1617
}
17-
const mockFolders: MockFolderModel[] = await MockFolder.find()
18-
const mocks: MockModel[] = await Mock.find({ parentId: null })
18+
const mockFolders: MockFolderModel[] = await MockFolder.find({ parentId: Constants.rootPath })
19+
const mocks: MockModel[] = await Mock.find({ parentId: Constants.rootPath })
1920
const response: ApiResponse = ApiResponse.success(MockFolderHelper.toJson(root, mockFolders, mocks))
2021
res.status(200).json(response)
2122
} catch (error: unknown) {

0 commit comments

Comments
 (0)