diff --git a/package.json b/package.json index 07b61b070b37451cf746c131c394561930aa7ea1..083bd104cff7f73ecae7358d570a2dbfe97f0541 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,6 @@ "devDependencies": { "@types/bcrypt": "^5.0.2", "@types/bcryptjs": "^3.0.0", - "@types/express": "^4.17.21", - "@types/express": "^5.0.0", - "@types/express": "^5.0.0", "@types/express": "^5.0.0", "@types/jsonwebtoken": "^9.0.9", "@types/node": "^22.13.9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 761a4e2d132692050748c4aa3cdd7d25212d1a6c..6c992b826648073c4d3fff0a8ea52e25cb904bc8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,7 +22,7 @@ importers: version: 12.0.1 drizzle-orm: specifier: ^0.40.0 - version: 0.40.0(@types/pg@8.11.11)(gel@2.0.1)(pg@8.14.0)(postgres@3.4.5) + version: 0.40.1(@types/pg@8.11.11)(gel@2.0.1)(pg@8.14.1)(postgres@3.4.5) express: specifier: ^4.21.2 version: 4.21.2 @@ -31,7 +31,7 @@ importers: version: 9.0.2 pg: specifier: ^8.13.3 - version: 8.14.0 + version: 8.14.1 postgres: specifier: ^3.4.5 version: 3.4.5 @@ -47,7 +47,7 @@ importers: version: 3.0.0 '@types/express': specifier: ^5.0.0 - version: 5.0.0 + version: 5.0.1 '@types/jsonwebtoken': specifier: ^9.0.9 version: 9.0.9 @@ -552,8 +552,8 @@ packages: '@types/express-serve-static-core@5.0.6': resolution: {integrity: sha512-3xhRnjJPkULekpSzgtoNYYcTWgEZkp4myc+Saevii5JPnHNvHMRlBSHDbs7Bh1iPPoVTERHEZXyhyLbMEsExsA==} - '@types/express@5.0.0': - resolution: {integrity: sha512-DvZriSMehGHL1ZNLzi6MidnsDhUZM/x2pRdDIKdwbUNqqwHxMlRdkxtn6/EPKyqKpHqTl/4nRZsRNLpZxZRpPQ==} + '@types/express@5.0.1': + resolution: {integrity: sha512-UZUw8vjpWFXuDnjFTh7/5c2TWDlQqeXHi6hcN7F2XSVT5P+WmUnnbFS3KA6Jnc6IsEqI2qCVu2bK0R0J4A8ZQQ==} '@types/http-errors@2.0.4': resolution: {integrity: sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==} @@ -739,8 +739,8 @@ packages: resolution: {integrity: sha512-l6dMSE100u7sDaTbLczibrQZjA35jLsHNqIV+jmhNVO3O8jzM6kywMOmV9uOz9ZVSCMPQhAZEFjL/qDPVrqpUA==} hasBin: true - drizzle-orm@0.40.0: - resolution: {integrity: sha512-7ptk/HQiMSrEZHnAsSlBESXWj52VwgMmyTEfoNmpNN2ZXpcz13LwHfXTIghsAEud7Z5UJhDOp8U07ujcqme7wg==} + drizzle-orm@0.40.1: + resolution: {integrity: sha512-aPNhtiJiPfm3qxz1czrnIDkfvkSdKGXYeZkpG55NPTVI186LmK2fBLMi4dsHpPHlJrZeQ92D322YFPHADBALew==} peerDependencies: '@aws-sdk/client-rds-data': '>=3' '@cloudflare/workers-types': '>=4' @@ -1170,8 +1170,8 @@ packages: resolution: {integrity: sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==} engines: {node: '>=10'} - pg@8.14.0: - resolution: {integrity: sha512-nXbVpyoaXVmdqlKEzToFf37qzyeeh7mbiXsnoWvstSqohj88yaa/I/Rq/HEVn2QPSZEuLIJa/jSpRDyzjEx4FQ==} + pg@8.14.1: + resolution: {integrity: sha512-0TdbqfjwIun9Fm/r89oB7RFQ0bLgduAhiIqIXOsyKoiC/L54DbuAAzIEN/9Op0f1Po9X7iCPXGoa/Ah+2aI8Xw==} engines: {node: '>= 8.0.0'} peerDependencies: pg-native: '>=3.0.1' @@ -1683,16 +1683,10 @@ snapshots: '@types/bcrypt@5.0.2': dependencies: '@types/node': 22.13.10 -<<<<<<< HEAD -<<<<<<< HEAD '@types/bcryptjs@3.0.0': dependencies: bcryptjs: 3.0.2 -======= ->>>>>>> baa1360 ( consertado) -======= ->>>>>>> a20601a32052cb95406df2e75d8114de3dc95e7b '@types/body-parser@1.19.5': dependencies: @@ -1710,11 +1704,10 @@ snapshots: '@types/range-parser': 1.2.7 '@types/send': 0.17.4 - '@types/express@5.0.0': + '@types/express@5.0.1': dependencies: '@types/body-parser': 1.19.5 '@types/express-serve-static-core': 5.0.6 - '@types/qs': 6.9.18 '@types/serve-static': 1.15.7 '@types/http-errors@2.0.4': {} @@ -1889,11 +1882,11 @@ snapshots: transitivePeerDependencies: - supports-color - drizzle-orm@0.40.0(@types/pg@8.11.11)(gel@2.0.1)(pg@8.14.0)(postgres@3.4.5): + drizzle-orm@0.40.1(@types/pg@8.11.11)(gel@2.0.1)(pg@8.14.1)(postgres@3.4.5): optionalDependencies: '@types/pg': 8.11.11 gel: 2.0.1 - pg: 8.14.0 + pg: 8.14.1 postgres: 3.4.5 dunder-proto@1.0.1: @@ -2302,9 +2295,9 @@ snapshots: pg-numeric@1.0.2: {} - pg-pool@3.8.0(pg@8.14.0): + pg-pool@3.8.0(pg@8.14.1): dependencies: - pg: 8.14.0 + pg: 8.14.1 pg-protocol@1.8.0: {} @@ -2326,10 +2319,10 @@ snapshots: postgres-interval: 3.0.0 postgres-range: 1.1.4 - pg@8.14.0: + pg@8.14.1: dependencies: pg-connection-string: 2.7.0 - pg-pool: 3.8.0(pg@8.14.0) + pg-pool: 3.8.0(pg@8.14.1) pg-protocol: 1.8.0 pg-types: 2.2.0 pgpass: 1.0.5 diff --git a/src/db/migrations/0000_careful_brother_voodoo.sql b/src/db/migrations/0000_careful_brother_voodoo.sql new file mode 100644 index 0000000000000000000000000000000000000000..33355cc0fdf9d11a6fe6c5382cb206454b3d3627 --- /dev/null +++ b/src/db/migrations/0000_careful_brother_voodoo.sql @@ -0,0 +1,38 @@ +CREATE TYPE "public"."bodyPartsEnum" AS ENUM('FrontalCortex', 'OperatingSystem', 'Arms', 'Skeleton', 'NervousSystem', 'IntegumentarySystem', 'Face', 'Hands', 'CirculatorySystem', 'Legs');--> statement-breakpoint +CREATE TABLE "implants" ( + "id" serial PRIMARY KEY NOT NULL, + "nome" varchar(255) NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "price" numeric NOT NULL, + "cyberCost" numeric DEFAULT '5', + "bodyPart" varchar(255) NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "implants_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE "pursaches" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "pursaches_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE "users" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "password" varchar(255) NOT NULL, + "email" varchar(255) NOT NULL, + "birthday" timestamp NOT NULL, + "cpf" varchar(11) NOT NULL, + "money" numeric DEFAULT '0' NOT NULL, + "cyberpsychosis" numeric DEFAULT '0' NOT NULL, + "cyberLimit" numeric DEFAULT '100' NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "users_id_unique" UNIQUE("id"), + CONSTRAINT "users_email_unique" UNIQUE("email"), + CONSTRAINT "users_cpf_unique" UNIQUE("cpf") +); +--> statement-breakpoint +ALTER TABLE "pursaches" ADD CONSTRAINT "pursaches_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pursaches" ADD CONSTRAINT "pursaches_user_id_implants_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."implants"("id") ON DELETE cascade ON UPDATE no action; \ No newline at end of file diff --git a/src/db/migrations/0000_pale_venus.sql b/src/db/migrations/0000_pale_venus.sql deleted file mode 100644 index e1583e6e40215bac969fc819b68deed61517736f..0000000000000000000000000000000000000000 --- a/src/db/migrations/0000_pale_venus.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE "implants" ( - "id" serial PRIMARY KEY NOT NULL, - "nome" varchar(255) NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "price" numeric NOT NULL, - "cyberCost" numeric DEFAULT 5, - "bodyPart" varchar(255) NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "implants_id_unique" UNIQUE("id") -); - diff --git a/src/db/migrations/0001_jittery_vermin.sql b/src/db/migrations/0001_jittery_vermin.sql deleted file mode 100644 index 71f0d9f2b63fd9ca9b62175c1e7c5e9d6e9e8032..0000000000000000000000000000000000000000 --- a/src/db/migrations/0001_jittery_vermin.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE "user" DISABLE ROW LEVEL SECURITY;--> statement-breakpoint -DROP TABLE "user" CASCADE;--> statement-breakpoint -ALTER TABLE "implants" ALTER COLUMN "cyberCost" SET DEFAULT '5'; \ No newline at end of file diff --git a/src/db/migrations/meta/0000_snapshot.json b/src/db/migrations/meta/0000_snapshot.json new file mode 100644 index 0000000000000000000000000000000000000000..7ca0e6ae9b1447058b8f06287357e3a5217ba9e0 --- /dev/null +++ b/src/db/migrations/meta/0000_snapshot.json @@ -0,0 +1,275 @@ +{ + "id": "c768b134-ce6b-49d5-b919-99dd99232ad7", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.implants": { + "name": "implants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "nome": { + "name": "nome", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "price": { + "name": "price", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "cyberCost": { + "name": "cyberCost", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'5'" + }, + "bodyPart": { + "name": "bodyPart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "implants_id_unique": { + "name": "implants_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pursaches": { + "name": "pursaches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "pursaches_user_id_users_id_fk": { + "name": "pursaches_user_id_users_id_fk", + "tableFrom": "pursaches", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pursaches_user_id_implants_id_fk": { + "name": "pursaches_user_id_implants_id_fk", + "tableFrom": "pursaches", + "tableTo": "implants", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pursaches_id_unique": { + "name": "pursaches_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "birthday": { + "name": "birthday", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "cpf": { + "name": "cpf", + "type": "varchar(11)", + "primaryKey": false, + "notNull": true + }, + "money": { + "name": "money", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "cyberpsychosis": { + "name": "cyberpsychosis", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "cyberLimit": { + "name": "cyberLimit", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'100'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_id_unique": { + "name": "users_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "users_cpf_unique": { + "name": "users_cpf_unique", + "nullsNotDistinct": false, + "columns": [ + "cpf" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.bodyPartsEnum": { + "name": "bodyPartsEnum", + "schema": "public", + "values": [ + "FrontalCortex", + "OperatingSystem", + "Arms", + "Skeleton", + "NervousSystem", + "IntegumentarySystem", + "Face", + "Hands", + "CirculatorySystem", + "Legs" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/db/migrations/meta/0001_snapshot.json b/src/db/migrations/meta/0001_snapshot.json deleted file mode 100644 index 5adacb40de2bd232ffb137f270402ba798591532..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0001_snapshot.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "id": "4d3fe86b-c3c5-4ca8-b4dc-e6decec7f7fd", - "prevId": "faff4eaf-f912-450c-a6e4-6a24cf819ee3", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.implants": { - "name": "implants", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "nome": { - "name": "nome", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "price": { - "name": "price", - "type": "numeric", - "primaryKey": false, - "notNull": true - }, - "cyberCost": { - "name": "cyberCost", - "type": "numeric", - "primaryKey": false, - "notNull": false, - "default": "'5'" - }, - "bodyPart": { - "name": "bodyPart", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "implants_id_unique": { - "name": "implants_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - }, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - } - }, - "enums": {}, - "schemas": {}, - "sequences": {}, - "roles": {}, - "policies": {}, - "views": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index 1a1350f39f0f4b785dc4c4aaa491884e8f0605f4..7d0d579fc50188f494ef979a2ce0a5c51dc78a36 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -1,6 +1,3 @@ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD { "version": "7", "dialect": "postgresql", @@ -8,25 +5,9 @@ { "idx": 0, "version": "7", - "when": 1741954948675, - "tag": "0000_pale_venus", - "breakpoints": true - }, - { - "idx": 1, - "version": "7", - "when": 1741956579745, - "tag": "0001_jittery_vermin", + "when": 1742480310673, + "tag": "0000_careful_brother_voodoo", "breakpoints": true } ] -} -======= -{"version":"7","dialect":"postgresql","entries":[]} ->>>>>>> f75e135 (Issue#1: ADD user schema) -======= -{"version":"7","dialect":"postgresql","entries":[]} ->>>>>>> baa1360 ( consertado) -======= -{"version":"7","dialect":"postgresql","entries":[]} ->>>>>>> a20601a32052cb95406df2e75d8114de3dc95e7b +} \ No newline at end of file diff --git a/src/handlers/user.ts b/src/handlers/user.ts index 36041a6b977a662da0dbf21cfb28bfc3934c0626..a86c46231aa1954ed64e617379632534edcf3323 100644 --- a/src/handlers/user.ts +++ b/src/handlers/user.ts @@ -23,7 +23,7 @@ export default class User{ } - static async updateUser (id: number, req: Request, res:Response){ + static async updateUser (id: number, req: Request, res:Response): Promise<any>{ if (!this.userRequestValidation(req)) { return res.status(400).json({ erro: "Invalid Request" }); @@ -58,7 +58,7 @@ export default class User{ return res.status(200).json({ message: "User Updated Successfully "}); } - static async deleteUser (id: number, req: Request, res: Response){ + static async deleteUser (id: number, req: Request, res: Response): Promise<any>{ if (!this.userRequestValidation(req)) { return res.status(400).json({ error: "Invalid Request" });; @@ -76,7 +76,7 @@ export default class User{ return res.status(408).json({ error: "Error during user deletion" }); } } - static createUser = async (req: Request, res: Response) => { + static createUser = async (req: Request, res: Response): Promise<any> => { try { // validar com o Zod @@ -109,7 +109,7 @@ export default class User{ } } - static readUser = async (req: Request, res: Response) => { + static readUser = async (req: Request, res: Response): Promise<any> => { try { // extrair id e nome da requisição @@ -145,7 +145,7 @@ export default class User{ } } - static loginUser = async (req: Request, res: Response) => { + static loginUser = async (req: Request, res: Response): Promise<any> => { try { const { email, password } = req.body; diff --git a/src/index.ts b/src/index.ts index 120d5edc0680845a4423e894ed1f9479083eac66..389b9d71a9c9935398dbd0281fe5507db61bdd49 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ import express, { urlencoded, json } from 'express' import dotenv from 'dotenv' import User from './handlers/user'; -import Implant from '@/handlers/implants' -import { Auth } from '@/middleware/auth' +import Implant from './handlers/implants' +import { tokenAuthenticator } from '@/middleware/auth' // Carregar variáveis de ambiente dotenv.config()