-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented create task and list tasks in api + app
- Loading branch information
Showing
55 changed files
with
324 additions
and
3,406 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,27 @@ | ||
name: CD | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run Prisma migrations | ||
run: npx prisma migrate dev | ||
|
||
- name: Apply migrations to prod DB | ||
run: npx prisma db push --preview-feature |
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,34 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Lint code | ||
run: npm run lint | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
- name: Test | ||
run: npm run test |
5 changes: 5 additions & 0 deletions
5
apps/api-v2/prisma/migrations/20230913181514_remove_task_user_fk/migration.sql
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,5 @@ | ||
-- DropForeignKey | ||
ALTER TABLE `Task` DROP FOREIGN KEY `Task_userId_fkey`; | ||
|
||
-- RenameIndex | ||
ALTER TABLE `Task` RENAME INDEX `Task_userId_fkey` TO `owner_id_idx`; |
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
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,74 @@ | ||
import { Router } from "express"; | ||
import { authenticateJWTMiddleware, validateRequestSchema } from "../mws"; | ||
import { getAuthContext } from "../utils"; | ||
import { prisma } from "../db"; | ||
import { SupernovaResponse } from "../types"; | ||
import { createTaskRequestSchema } from "@supernova/types"; | ||
|
||
export const buildTasksRouter = () => { | ||
const router = Router(); | ||
|
||
router.get("/tasks", authenticateJWTMiddleware, async (req, res) => { | ||
try { | ||
const authCtx = getAuthContext(req); | ||
// get all tasks for the user | ||
const tasks = await prisma.task.findMany({ | ||
where: { | ||
userId: authCtx.sub, | ||
}, | ||
}); | ||
return res.status(200).json( | ||
new SupernovaResponse({ | ||
message: "Tasks fetched successfully", | ||
data: tasks, | ||
}) | ||
); | ||
} catch (err) { | ||
let e = err as Error; | ||
return res.status(500).json( | ||
new SupernovaResponse({ | ||
message: e.message, | ||
error: "Internal Server Error", | ||
}) | ||
); | ||
} | ||
}); | ||
|
||
// create task | ||
router.post( | ||
"/tasks", | ||
authenticateJWTMiddleware, | ||
validateRequestSchema(createTaskRequestSchema), | ||
async (req, res) => { | ||
try { | ||
const authCtx = getAuthContext(req); | ||
const task = await prisma.task.create({ | ||
data: { | ||
title: req.body.title, | ||
description: req.body.description, | ||
startAt: req.body.startAt, | ||
expectedDurationSeconds: req.body.expectedDurationSeconds, | ||
userId: authCtx.sub, | ||
}, | ||
}); | ||
return res.status(200).json( | ||
new SupernovaResponse({ | ||
message: "Task created successfully", | ||
data: task, | ||
}) | ||
); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
console.error(e); | ||
return res.status(500).json( | ||
new SupernovaResponse({ | ||
message: e.message, | ||
error: "Internal Server Error", | ||
}) | ||
); | ||
} | ||
} | ||
} | ||
); | ||
return 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
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 { Request } from "express"; | ||
import { IAuthCtx } from "./types"; | ||
|
||
export const getAuthContext = (req: Request): IAuthCtx => { | ||
return req.user as IAuthCtx; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.