Skip to content

Commit

Permalink
Json Store
Browse files Browse the repository at this point in the history
  • Loading branch information
XboxBedrock authored Jul 8, 2024
1 parent 4ebd4c3 commit 59046c0
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
8 changes: 8 additions & 0 deletions prisma/migrations/20240608223545_add_json_store/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- CreateTable
CREATE TABLE "JsonStore" (
"id" TEXT NOT NULL,
"data" JSONB NOT NULL,

CONSTRAINT "JsonStore_pkey" PRIMARY KEY ("id")
);

5 changes: 5 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ model CalendarEvent {
buildTeamId String?
}

model JsonStore {
id String @id @default(uuid())
data Json
}

enum ApplicationStatus {
SEND
REVIEWING
Expand Down
90 changes: 90 additions & 0 deletions src/controllers/GeneralController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,96 @@ class GeneralController {

res.send(upload);
}

public async setJsonStore(req: Request, res: Response) {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return ERROR_VALIDATION(req, res, errors.array());
}
const errors = validationResult(req);
if (!errors.isEmpty()) {
return ERROR_VALIDATION(req, res, errors.array());
}

if (!req.kauth) {
return ERROR_GENERIC(req, res, 500, "Unidentified User.");
}

const id = req.params.id

if (!id) {

This comment has been minimized.

Copy link
@Nudelsuppe42

Nudelsuppe42 Jul 8, 2024

Contributor

You can just use validations from web/routes/index.ts 👯

return ERROR_GENERIC(req, res, 404, "ID not found.");
}

const jsonBody = req.body

if (!body) {

This comment has been minimized.

Copy link
@Nudelsuppe42

Nudelsuppe42 Jul 8, 2024

Contributor

Same as above

return ERROR_GENERIC(req, res, 404, "Body not found.");
}


const upload = await this.core.getPrisma().jsonStore.findUnique({
where: {
id: id,
}
})

if (!upload) {
await this.core.getPrisma().jsonStore.create({
data: {
id: id
data: jsonBody
}
})
} else {
await this.core.getPrisma().jsonStore.update({
where: {
id: id
}
data: {
id: id
data: jsonBody
}
})
}

res.send(body)
}

This comment has been minimized.

Copy link
@Nudelsuppe42

Nudelsuppe42 Jul 8, 2024

Contributor

jsonStore.upsert exists :p


public async getJsonStore(req: Request, res: Response) {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return ERROR_VALIDATION(req, res, errors.array());
}

if (!req.kauth) {
return ERROR_GENERIC(req, res, 500, "Unidentified User.");
}

const id = req.params.id

if (!id) {

This comment has been minimized.

Copy link
@Nudelsuppe42

Nudelsuppe42 Jul 8, 2024

Contributor

Validation inside web/routes

return ERROR_GENERIC(req, res, 404, "ID not found.");
}


const upload = await this.core.getPrisma().jsonStore.findUnique({
where: {
id: id,
},
select: {

This comment has been minimized.

Copy link
@Nudelsuppe42

Nudelsuppe42 Jul 8, 2024

Contributor

Unneeded, only this exists

data: true,
},
})

if (!upload) {
return ERROR_GENERIC(req, res, 404, "ID not found.");
}

res.send(upload.data)

}

}

export default GeneralController;
18 changes: 18 additions & 0 deletions src/web/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ class Routes {
query("claim").isUUID().optional(),
this.web.getFileUpload().single("image")
);
router.addRoute(
RequestMethods.GET,
"/jsonstore/:id",
async (request, response) => {
await controllers.general.getJsonStore(request, response);
},
param("id")

This comment has been minimized.

Copy link
@Nudelsuppe42

Nudelsuppe42 Jul 8, 2024

Contributor

add .isString()

);

router.addRoute(
RequestMethods.POST,
"/jsonstore/:id",
async (request, response) => {
await controllers.general.setJsonStore(request, response);
},
param("id")

This comment has been minimized.

Copy link
@Nudelsuppe42

Nudelsuppe42 Jul 8, 2024

Contributor

add .isString() and add body("jsonData").isString()

);

router.addRoute(
RequestMethods.POST,
"/coords",
Expand Down

0 comments on commit 59046c0

Please sign in to comment.