forked from b00tc4mp/isdi-bootcamp-202405
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create Schema model and index of model in cor/data b00tc4mp#101
- Loading branch information
1 parent
3d61dd5
commit b3b6372
Showing
5 changed files
with
331 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const data = {} | ||
|
||
export default data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters