Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ typings/
.yarn-integrity

# dotenv environment variables file
.env
.env.test
*.env
*.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
"scripts": {
"start": " yarn tsc && node build/index.js",
"typeorm": "npx ts-node ./node_modules/typeorm/cli.js",
"dev":"ts-node-dev --respawn --transpile-only --inspect=0.0.0.0:7001 --exit-child --respawn src/server.ts"
"dev": "ts-node-dev --respawn --transpile-only --inspect=0.0.0.0:7001 --exit-child --respawn src/server.ts"
},
"dependencies": {
"@types/cors": "^2.8.8",
"@types/express": "^4.17.9",
"@types/morgan": "^1.9.2",
"@types/node": "^14.14.9",
"@types/swagger-ui-express": "^4.1.2",
"@types/uuid": "^8.3.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
Expand All @@ -24,10 +18,18 @@
"mysql2": "^2.2.5",
"reflect-metadata": "^0.1.13",
"swagger-ui-express": "^4.1.5",
"ts-node": "^9.0.0",
"ts-node-dev": "^1.0.0",
"typeorm": "^0.2.29",
"typescript": "^4.0.5",
"uuid": "^8.3.1"
},
"devDependencies": {
"@types/cors": "^2.8.8",
"@types/express": "^4.17.9",
"@types/morgan": "^1.9.2",
"@types/node": "^14.14.9",
"@types/swagger-ui-express": "^4.1.2",
"@types/uuid": "^8.3.0",
"ts-node": "^9.0.0",
"ts-node-dev": "^1.0.0"
}
}
File renamed without changes.
File renamed without changes.
82 changes: 42 additions & 40 deletions src/Repository/database/UserDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,57 @@ import { getRepository } from "typeorm";
import Messenger from "../../Domain/models/Messenger";
import UserEntity from "../entities/UserEntity";

class UserDatabase{
async index(){
try{
const repository = getRepository(UserEntity);
let users = await repository.find();
return users;
}catch(er){
throw er;
}
export async function index(){
try{
const repository = getRepository(UserEntity);
let users = await repository.find();
return users;
}catch(er){
throw er;
}
}

async create(user: UserEntity){
try{
const repository = getRepository(UserEntity);
const userExist = await repository.findOne({where:{CPF:user.CPF}});
if(!userExist){
let newUser = repository.create(user);
repository.save(newUser);
return new Messenger({status:true, message:"Usuário criado com sucesso!"});
}
export async function create(user: UserEntity){
try{
const repository = getRepository(UserEntity);


const userExist = await repository.findOne({where:{CPF:user.CPF}});
if(!userExist){
let newUser = repository.create(user);
repository.save(newUser);
return new Messenger({status:true, message:"Usuário criado com sucesso!"});
}

return new Messenger({status:false,message:"Esse usuário já existe!"});
return new Messenger({status:false,message:"Esse usuário já existe!"});

}catch(ex){
throw (ex);
}
}catch(ex){
throw (ex);
}
}

async getUser(CPF:string){
try{
const repository = getRepository(UserEntity);
let user = await repository.findOne({where:{CPF:CPF}});
if(user){
return new Messenger({
status:true,
data:user
});
}
export async function getUser(CPF:string){
try{
const repository = getRepository(UserEntity);
let user = await repository.findOne({where:{CPF:CPF}});
if(user){
return new Messenger({
status:false,
message:"User not found"
status:true,
data:user
});

}catch(er){
throw er
}
return new Messenger({
status:false,
message:"User not found"
});

}catch(er){
throw er
}
}

export default new UserDatabase();
export default {
index,
create,
getUser
};
45 changes: 21 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,7 @@ chalk@^1.1.1:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^4.1.0:
chalk@^4.0.0, chalk@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a"
integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==
Expand All @@ -318,15 +310,15 @@ chokidar@^3.4.0:
fsevents "~2.1.2"

cli-highlight@^2.1.4:
version "2.1.4"
resolved "https://registry.yarnpkg.com/cli-highlight/-/cli-highlight-2.1.4.tgz#098cb642cf17f42adc1c1145e07f960ec4d7522b"
integrity sha512-s7Zofobm20qriqDoU9sXptQx0t2R9PEgac92mENNm7xaEe1hn71IIMsXMK+6encA6WRCWWxIGQbipr3q998tlQ==
version "2.1.8"
resolved "https://registry.yarnpkg.com/cli-highlight/-/cli-highlight-2.1.8.tgz#aa3130b481649d631ab913ae60becf81c69c3887"
integrity sha512-mFuTW5UOV3/S0wZE9/1b0EcAM0XOJIhoAWPhWm5voiJ6ugVBkvYBIEL7sbHo9sEtWdEmwDIWab32qpaRI3cfqQ==
dependencies:
chalk "^3.0.0"
highlight.js "^9.6.0"
chalk "^4.0.0"
highlight.js "^10.0.0"
mz "^2.4.0"
parse5 "^5.1.1"
parse5-htmlparser2-tree-adapter "^5.1.1"
parse5-htmlparser2-tree-adapter "^6.0.0"
yargs "^15.0.0"

cliui@^6.0.0:
Expand Down Expand Up @@ -679,10 +671,10 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"

highlight.js@^9.6.0:
version "9.18.5"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.18.5.tgz#d18a359867f378c138d6819edfc2a8acd5f29825"
integrity sha512-a5bFyofd/BHCX52/8i8uJkjr9DYwXIPnM/plwI6W7ezItLGqzt7X2G2nXuYSfsIJdkwwj/g9DG1LkcGJI/dDoA==
highlight.js@^10.0.0:
version "10.4.0"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.4.0.tgz#ef3ce475e5dfa7a48484260b49ea242ddab823a0"
integrity sha512-EfrUGcQ63oLJbj0J0RI9ebX6TAITbsDBLbsjr881L/X5fMO9+oadKzEF21C7R3ULKG6Gv3uoab2HiqVJa/4+oA==

hosted-git-info@^2.1.4:
version "2.8.8"
Expand Down Expand Up @@ -1091,18 +1083,23 @@ parse-json@^2.2.0:
dependencies:
error-ex "^1.2.0"

parse5-htmlparser2-tree-adapter@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-5.1.1.tgz#e8c743d4e92194d5293ecde2b08be31e67461cbc"
integrity sha512-CF+TKjXqoqyDwHqBhFQ+3l5t83xYi6fVT1tQNg+Ye0JRLnTxWvIroCjEp1A0k4lneHNBGnICUf0cfYVYGEazqw==
parse5-htmlparser2-tree-adapter@^6.0.0:
version "6.0.1"
resolved "https://registry.yarnpkg.com/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz#2cdf9ad823321140370d4dbf5d3e92c7c8ddc6e6"
integrity sha512-qPuWvbLgvDGilKc5BoicRovlT4MtYT6JfJyBOMDsKoiT+GiuP5qyrPCnR9HcPECIJJmZh5jRndyNThnhhb/vlA==
dependencies:
parse5 "^5.1.1"
parse5 "^6.0.1"

parse5@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178"
integrity sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==

parse5@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b"
integrity sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==

parseurl@~1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4"
Expand Down