Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //pessoas
- 'use strict'
- const mongoose = require('mongoose');
- const Schema = mongoose.Schema;
- let ObjectID = Schema.ObjectId;
- const schemaStructure = {
- person : {
- first_name : { type: String }
- ,last_name : { type: String }
- ,birthdate : { type: Date }
- ,document_number : { type: String }
- ,add_company : { type: Boolean, default: false }
- ,company_code : { type: ObjectID, ref: 'company'}
- ,is_dealer : { type: Boolean, default: false }
- ,is_provider : { type: Boolean, default: false }
- }
- ,contact : {
- phone : { type: String }
- ,mobile : { type: String }
- ,email : { type: String }
- }
- ,address : {
- street : { type: String }
- ,number : { type: Number }
- ,district : { type: String }
- ,city : { type: String }
- ,state : { type: String }
- ,zip_code : { type: String }
- ,reference : { type: String }
- }
- ,created_at : { type: Date, default: Date.now }
- ,updated_at : { type: Date }
- };
- const personSchema = new Schema(schemaStructure);
- module.exports = mongoose.model('person', personSchema, 'people');
- //empresas
- 'use strict'
- const mongoose = require('mongoose');
- const Schema = mongoose.Schema;
- const schemaStructure = {
- company : {
- name : { type: String }
- ,document_number : { type: Number }
- ,is_provider : { type: Boolean, default: false }
- }
- ,contact : {
- phone : { type: String }
- ,email : { type: String }
- }
- ,address : {
- city : { type: String }
- ,state : { type: String }
- ,zip_code : { type: Number }
- }
- ,created_at : { type: Date, default: Date.now }
- ,updated_at : { type: Date }
- };
- const company = new Schema(schemaStructure);
- module.exports = mongoose.model('company', company, 'companies');
- //rota
- router.get('/', (req, res) => {
- Person.find()
- .populate('person.company_code')
- .exec((err, data) => {
- if(err) return res.json({'Erro': 'GET/'})
- return res.json(data)
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement