Skip to content

Commit

Permalink
create Schema model and index of model in cor/data b00tc4mp#101
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasOrtsBaguena committed Aug 10, 2024
1 parent 3d61dd5 commit b3b6372
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 1 deletion.
3 changes: 3 additions & 0 deletions staff/lucas-orts/project/cor/data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const data = {}

export default data
82 changes: 82 additions & 0 deletions staff/lucas-orts/project/cor/data/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Schema, model, Types } from 'mongoose'

const { ObjectId } = Types

const user = new Schema({
name: {
type: String,
required: true
},
surname: {
type: String,
required: true
},
email: {
type: String,
required: true,
unique: true
},
phone: {
type: String,
required: true,
unique: true
},
address: {
type: String,
required: true
},
password: {
type: String,
required: true
},
location: {
type: [Number],
validate: {
validator: function (arr) {
return arr.length === 2
},
message: 'The array must contain exactly two numbers.'
}
}
})

const product = new Schema({
farmer: {
type: ObjectId,
required: true,
ref: 'User'
},
name: {
type: String,
required: true
},
type: {
type: String
},
image: {
type: String,
required: true
},
location: {
type: [Number],
validate: {
validator: function (arr) {
return arr.length === 2
},
message: 'The array must contain exactly two numbers.'
}
},
enabled: {
type: Boolean,
required: true,
default: true
}
})

const User = model('User', user)
const Product = model('Product', product)

export {
User,
Product
}
230 changes: 230 additions & 0 deletions staff/lucas-orts/project/cor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions staff/lucas-orts/project/cor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "cor",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"mongoose": "^8.5.2"
}
}
2 changes: 1 addition & 1 deletion staff/lucas-orts/project/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Aplicación que permite ver los agricultores ecológicos cerca de tu zona así como todos los productos(frutas y verduras), que tiene cada un de los agricultores


![Pony Image](https://ojeandolaagenda.com/wp-content/uploads/2010/07/logo.png)
![Eco Image](https://ojeandolaagenda.com/wp-content/uploads/2010/07/logo.png)


## Functional
Expand Down

0 comments on commit b3b6372

Please sign in to comment.