Skip to content

Commit

Permalink
feat: Generate uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
arbezerra committed Jun 29, 2023
1 parent 9f3cfe7 commit 2783cf1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import User from "../models/user";
import jwt from "jsonwebtoken";
import { ValidateMethod } from "../middlewares/validate";
import { z } from "zod";
import { v4 as uuid4 } from "uuid";

const AuthController = {
index: async (req: Request, res: Response) => {
Expand Down Expand Up @@ -32,6 +33,7 @@ const AuthController = {
{
...req.body,
password: await hash(password),
id: uuid4(),
},
"id"
);
Expand Down
9 changes: 4 additions & 5 deletions controllers/category.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { NextFunction, Request, Response } from "express";
import { Request, Response } from "express";
import pool from "../lib/db";
import { verify } from "../lib/hash";
import User from "../models/user";
import jwt from "jsonwebtoken";
import Category from "../models/category";
import { ValidateMethod } from "../middlewares/validate";
import { z } from "zod";
import { v4 as uuid4 } from "uuid";

const CategoryController = {
index: async (req: Request, res: Response) => {
Expand All @@ -25,7 +23,8 @@ const CategoryController = {
return res.status(200).json(item);
},
store: async (req: Request, res: Response) => {
const item = await pool<Category>("categories").insert(req.body);
req.body.id = uuid4();
const item = await pool<Category>("categories").insert(req.body, "id");
return res.status(200).json(item);
},
update: async (req: Request, res: Response) => {
Expand Down
7 changes: 3 additions & 4 deletions controllers/post.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Request, Response } from "express";
import pool from "../lib/db";
import { verify } from "../lib/hash";
import User from "../models/user";
import jwt from "jsonwebtoken";
import Post from "../models/post";
import { ValidateMethod } from "../middlewares/validate";
import { z } from "zod";
import { v4 as uuid4 } from "uuid";

const PostController = {
index: async (req: Request, res: Response) => {
Expand All @@ -23,7 +21,8 @@ const PostController = {
return res.status(200).json(item);
},
store: async (req: Request, res: Response) => {
const item = await pool<Post>("posts").insert(req.body);
req.body.id = uuid4();
const item = await pool<Post>("posts").insert(req.body, "id");
return res.status(200).json(item);
},
update: async (req: Request, res: Response) => {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"sqlite3": "^5.1.6",
"uuid": "^9.0.0",
"zod": "^3.21.4"
},
"devDependencies": {
Expand All @@ -34,6 +35,7 @@
"@types/passport": "^1.0.12",
"@types/passport-jwt": "^3.0.8",
"@types/supertest": "^2.0.12",
"@types/uuid": "^9.0.2",
"jest": "^29.5.0",
"nodemon": "^2.0.22",
"superagent": "^8.0.9",
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
"sourceMap": false,
"removeComments": true
},
"exclude": [
"tests",
]
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,11 @@
dependencies:
"@types/superagent" "*"

"@types/uuid@^9.0.2":
version "9.0.2"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.2.tgz#ede1d1b1e451548d44919dc226253e32a6952c4b"
integrity sha512-kNnC1GFBLuhImSnV7w4njQkUiJi0ZXUycu1rUaouPqiKlXkh77JKgdRnTAp1x5eBwcIwbtI+3otwzuIDEuDoxQ==

"@types/yargs-parser@*":
version "21.0.0"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.0.tgz#0c60e537fa790f5f9472ed2776c2b71ec117351b"
Expand Down Expand Up @@ -3681,6 +3686,11 @@ utils-merge@1.0.1, utils-merge@^1.0.1:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==

uuid@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

v8-compile-cache-lib@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
Expand Down

0 comments on commit 2783cf1

Please sign in to comment.