-
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.
Merge pull request #30 from Jonhvmp/develop
Develop
- Loading branch information
Showing
18 changed files
with
482 additions
and
189 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,50 @@ | ||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages | ||
|
||
name: Node.js package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 12 | ||
- run: npm ci | ||
- run: npm test | ||
|
||
publish-npm: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 12 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm ci | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} | ||
|
||
publish-gpr: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 12 | ||
registry-url: $registry-url(npm) | ||
- run: npm ci | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import * as categoryService from '../services/snnipets/categoryService'; | ||
|
||
export const createCategory = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { name, description } = req.body; | ||
const userId = req.user?.id; | ||
|
||
if (!userId) { | ||
return res.status(401).json({ message: 'Usuário não autenticado.' }); | ||
} | ||
|
||
const category = await categoryService.createNewCategory(name, description, userId); | ||
res.status(201).json(category); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const getCategories = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const userId = req.user?.id; | ||
|
||
if (!userId) { | ||
return res.status(401).json({ message: 'Usuário não autenticado.' }); | ||
} | ||
|
||
const categories = await categoryService.getUserCategories(userId); | ||
res.json(categories); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const updateCategory = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { id } = req.params; | ||
const { name, description } = req.body; | ||
const userId = req.user?.id; | ||
|
||
if (!userId) { | ||
return res.status(401).json({ message: 'Usuário não autenticado.' }); | ||
} | ||
|
||
const category = await categoryService.updateCategory(id, name, description, userId); | ||
res.json(category); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const deleteCategory = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { id } = req.params; | ||
const userId = req.user?.id; | ||
|
||
if (!userId) { | ||
return res.status(401).json({ message: 'Usuário não autenticado.' }); | ||
} | ||
|
||
const result = await categoryService.removeCategory(id, userId); | ||
res.json(result); | ||
} 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
Oops, something went wrong.