-
-
Save anonymous/950a943c13042bc049bf054cda7fc7dd to your computer and use it in GitHub Desktop.
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
import mongoose from 'mongoose'; | |
const { Schema } = mongoose; | |
mongoose.Promise = global.Promise; | |
const imageSchema = new Schema({ | |
title: String, | |
categories: [{type: Schema.Types.ObjectId, ref: 'Category'}], | |
description: String, | |
path: String, | |
createdAt: {type: Date, default:Date.now}, | |
isDeleted: {type: Boolean, default: false} | |
}); | |
const Image = mongoose.model('Image', imageSchema); | |
export default Image; |
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
import mongoose from 'mongoose'; | |
const { Schema } = mongoose; | |
mongoose.Promise = global.Promise; | |
const categorySchema = new Schema({ | |
name: {type:String, ref:'Image'}, | |
createdAt: {type:Date, default: Date.now}, | |
isDeleted: {type: Boolean, default: false} | |
}); | |
const Category = mongoose.model('Category', categorySchema); | |
export default Category; |
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
imageController.getAll = (req,res)=>{ | |
db.Image.find({}).populate('categories') | |
.then( images =>{ | |
res.json(images) | |
}) | |
}; |
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
[ | |
{ | |
"_id": "590787970a477629a4dd45d3", | |
"title": "Bra Girl", | |
"description": "Girl portrait", | |
"path": "http://res.cloudinary.com/amazecpk/image/upload/v1493665693/acu1vuajlg1rklzfqduk.png", | |
"__v": 0, | |
"isDeleted": false, | |
"createdAt": "2017-05-01T19:08:07.441Z", | |
"categories": [ | |
{ | |
"_id": "58fc3d9fa5ed6233486cc977", | |
"name": "Personal", | |
"__v": 0, | |
"isDeleted": false, | |
"createdAt": "2017-04-23T05:37:35.352Z" | |
}, | |
{ | |
"_id": "58fc3dc0a5ed6233486cc979", | |
"name": "Portraits", | |
"__v": 0, | |
"isDeleted": false, | |
"createdAt": "2017-04-23T05:38:08.734Z" | |
} | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment