Skip to content

Commit

Permalink
[fix] - format
Browse files Browse the repository at this point in the history
Co-authored-by: saracampss <[email protected]>
  • Loading branch information
ingridSCarvalho and saracampss committed Aug 25, 2024
1 parent a4288e3 commit 41055bd
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 264 deletions.
64 changes: 32 additions & 32 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
version: '3.8'
version: "3.8"
services:
mongodb:
image: mongo:7.0
container_name: financedb
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
ports:
- "27018:27017"
env_file: .env
volumes:
- mongo-data:/data/db
networks:
- backend_network
command: ["mongod", "--quiet", "--logpath", "/dev/null"]
mongodb:
image: mongo:7.0
container_name: financedb
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
ports:
- "27018:27017"
env_file: .env
volumes:
- mongo-data:/data/db
networks:
- backend_network
command: ["mongod", "--quiet", "--logpath", "/dev/null"]

express_backend:
build: .
container_name: express_backend_finances
ports:
- "3002:3002"
env_file: .env
environment:
MONGO_URI: ${MONGO_URI}
depends_on:
- mongodb
networks:
- backend_network
volumes:
- ./:/app
express_backend:
build: .
container_name: express_backend_finances
ports:
- "3002:3002"
env_file: .env
environment:
MONGO_URI: ${MONGO_URI}
depends_on:
- mongodb
networks:
- backend_network
volumes:
- ./:/app

volumes:
mongo-data:
mongo-data:

networks:
backend_network:
backend_network:
92 changes: 47 additions & 45 deletions src/Controllers/supplierFormController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,70 @@ const SupplierForm = require("../Models/supplierFormSchema");
const util = require("../Util/utils");

const createSupplierForm = async (req, res) => {
try {
message = util.validator(req.body.supplierData);
try {
message = util.validator(req.body.supplierData);

if (message) {
return res.status(404).send({ erro: message });
}
if (message) {
return res.status(404).send({ erro: message });
}

const supplier = new SupplierForm(req.body.supplierData);
const supplier = new SupplierForm(req.body.supplierData);

await supplier.save();
return res.status(201).send(supplier);
} catch (error) {
return res.status(400).send(error);
}
await supplier.save();
return res.status(201).send(supplier);
} catch (error) {
return res.status(400).send(error);
}
};

const getSupplierForm = async (req, res) => {
try {
const supplier = await SupplierForm.find({});
return res.status(200).send(supplier);
} catch (error) {
return res.status(400).send(error);
}
try {
const supplier = await SupplierForm.find({});
return res.status(200).send(supplier);
} catch (error) {
return res.status(400).send(error);
}
};

const getSupplierFormById = async (req, res) => {
try {
const supplier = await SupplierForm.findById(req.params.id);
return res.status(200).send(supplier);
} catch (error) {
return res.status(400).send(error);
}
try {
const supplier = await SupplierForm.findById(req.params.id);
return res.status(200).send(supplier);
} catch (error) {
return res.status(400).send(error);
}
};

const deleteSupplierFormById = async (req, res) => {
try {
const deletedSupplier = await SupplierForm.findByIdAndDelete(req.params.id);
return res.status(200).send(deletedSupplier);
} catch (error) {
return res.status(400).send(error);
}
try {
const deletedSupplier = await SupplierForm.findByIdAndDelete(
req.params.id
);
return res.status(200).send(deletedSupplier);
} catch (error) {
return res.status(400).send(error);
}
};

const updateSupplierFormById = async (req, res) => {
try {
const updatedSupplier = await SupplierForm.findById(req.params.id);
if (!updatedSupplier) {
return res.status(404).send();
try {
const updatedSupplier = await SupplierForm.findById(req.params.id);
if (!updatedSupplier) {
return res.status(404).send();
}
Object.assign(updatedSupplier, req.body.supplierData);
updatedSupplier.updatedAt = new Date();
await updatedSupplier.save();
return res.status(200).send(updatedSupplier);
} catch (error) {
return res.status(400).send(error);
}
Object.assign(updatedSupplier, req.body.supplierData);
updatedSupplier.updatedAt = new Date();
await updatedSupplier.save();
return res.status(200).send(updatedSupplier);
} catch (error) {
return res.status(400).send(error);
}
};

module.exports = {
createSupplierForm,
getSupplierForm,
getSupplierFormById,
deleteSupplierFormById,
updateSupplierFormById,
createSupplierForm,
getSupplierForm,
getSupplierFormById,
deleteSupplierFormById,
updateSupplierFormById,
};
70 changes: 49 additions & 21 deletions src/Models/supplierFormSchema.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,97 @@
const mongoose = require('mongoose');
const mongoose = require("mongoose");

const supplierFormSchema = new mongoose.Schema({

nome: {
type: String,
required: true,
unique: true
unique: true,
},
tipoPessoa: {
type: String,
enum: ['Jurídica', 'Física', '']
enum: ["Jurídica", "Física", ""],
},
cpfCnpj: {
type: String,
unique: true,
},
statusFornecedor: {
type: String,
enum: ['Ativo', 'Inativo', '']
enum: ["Ativo", "Inativo", ""],
},
naturezaTransacao: {
type: String,
enum: ['Receita', 'Despesa', '']
enum: ["Receita", "Despesa", ""],
},
email: {
type: String,
unique: true,
sparse:true
sparse: true,
},
nomeContato: {
type: String
type: String,
},
celular: {
type: String,
unique: true,
sparse:true
sparse: true,
},
telefone: {
type: String,
unique: true,
sparse:true
sparse: true,
},
cep: {
type: String,
unique: true,
sparse:true
sparse: true,
},
cidade: {
type: String
type: String,
},
uf_endereco: {
type: String,
enum: ['AC', 'AL', 'AP', 'AM', 'BA', 'CE', 'DF', 'ES', 'GO', 'MA', 'MT', 'MS', 'MG', 'PA', 'PB', 'PR', 'PE', 'PI', 'RJ', 'RN', 'RS', 'RO', 'RR', 'SC', 'SP', 'SE', 'TO', '']
enum: [
"AC",
"AL",
"AP",
"AM",
"BA",
"CE",
"DF",
"ES",
"GO",
"MA",
"MT",
"MS",
"MG",
"PA",
"PB",
"PR",
"PE",
"PI",
"RJ",
"RN",
"RS",
"RO",
"RR",
"SC",
"SP",
"SE",
"TO",
"",
],
},
logradouro: {
type: String
type: String,
},
complemento: {
type: String
type: String,
},
nomeBanco: {
type: String
type: String,
},
agencia: {
type: String
type: String,
},
numeroBanco: {
type: String,
Expand All @@ -76,13 +104,13 @@ const supplierFormSchema = new mongoose.Schema({
},
createdAt: {
type: Date,
default: Date.now
default: Date.now,
},
updatedAt: {
type: Date,
default: Date.now
default: Date.now,
},
})
});

const supplierForm = mongoose.model('Supplier', supplierFormSchema);
const supplierForm = mongoose.model("Supplier", supplierFormSchema);
module.exports = supplierForm;
Loading

0 comments on commit 41055bd

Please sign in to comment.