This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { DatasetModel } from "../models/Dataset.model"; | ||
|
||
export const createDataset = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
const { name, workspace, project } = req.body; | ||
|
||
const dataset = await DatasetModel.create({ | ||
name, | ||
workspace, | ||
project, | ||
}); | ||
|
||
res.status(201).json({ | ||
dataset, | ||
message: "Dataset created", | ||
}); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { ProjectModel } from "../models/Project.model"; | ||
|
||
export const createProject = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
const { name, workspace } = req.body; | ||
|
||
const project = await ProjectModel.create({ | ||
name, | ||
workspace, | ||
}); | ||
|
||
res.status(201).json({ | ||
project, | ||
message: "Project created", | ||
}); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { z } from "zod"; | ||
|
||
export const createDatasetSchema = z.object({ | ||
name: z.string(), | ||
workspace: z.number(), | ||
project: z.number(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { z } from "zod"; | ||
|
||
export const createProjectSchema = z.object({ | ||
name: z.string(), | ||
workspace: z.number(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Router } from "express"; | ||
import { validate } from "../middlewares/validate"; | ||
import { createDataset } from "../controllers/dataset.controller"; | ||
import { createDatasetSchema } from "../middlewares/schemas/createDataset.schema"; | ||
|
||
const router = Router(); | ||
|
||
router.post("", validate(createDatasetSchema), createDataset); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import { Router } from "express"; | ||
import workspaceRouter from "./workspace.router"; | ||
import projectRouter from "./project.router"; | ||
import datasetRouter from "./dataset.router"; | ||
|
||
const router = Router(); | ||
|
||
// /api/v1/workspace | ||
router.use("/workspace", workspaceRouter); | ||
|
||
// /api/v1/project | ||
router.use("/project", projectRouter); | ||
|
||
// /api/v1/dataset | ||
router.use("/dataset", datasetRouter); | ||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Router } from "express"; | ||
import { createProject } from "../controllers/project.controller"; | ||
import { validate } from "../middlewares/validate"; | ||
import { createProjectSchema } from "../middlewares/schemas/createProject.schema"; | ||
|
||
const router = Router(); | ||
|
||
router.post("", validate(createProjectSchema), createProject); | ||
|
||
export default router; |