-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aggiunti modelli e API per allegati e commenti
l'API è solo un mockup e deve essere integrata con il middleware multer di express per la gestione dei file
- Loading branch information
Showing
6 changed files
with
146 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,44 @@ | ||
const ModelController = require('./ModelController'); | ||
const Attachment = require('../models/Attachment'); | ||
|
||
const fields = { | ||
"mimetype": { | ||
can_filter: true, | ||
}, | ||
"uploader_id": { | ||
can_filter: true, | ||
can_sort: true, | ||
match_id_object: true, | ||
}, | ||
"size": { | ||
can_filter: true, | ||
can_sort: true | ||
}, | ||
}; | ||
|
||
const AttachmentController = { | ||
|
||
index: async req => { | ||
return await ModelController.index(req, { | ||
Model: Attachment, | ||
fields | ||
}); | ||
}, | ||
|
||
view: async req => { | ||
return await ModelController.view(req, { | ||
Model: Attachment, | ||
fields | ||
}) | ||
}, | ||
|
||
post: async req => { | ||
// TODO: il contenuto dell'allegato deve essere gestito all'interno | ||
// di questo metodo, probabilmente utlizzando il middleware `multer` | ||
// per express, modificando poi il body all'occorrenza | ||
const attachment = new Attachment(req.body); | ||
return await attachment.save(); | ||
} | ||
} | ||
|
||
module.exports = AttachmentController; |
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,47 @@ | ||
const ModelController = require('./ModelController'); | ||
const Comment = require('../models/Comment'); | ||
|
||
const fields = { | ||
"creator_id": { | ||
can_filter: true, | ||
can_sort: true, | ||
match_id_object: true, | ||
}, | ||
"modifier_id": { | ||
can_filter: true, | ||
can_sort: true, | ||
match_id_object: true, | ||
}, | ||
"academic_year": { | ||
can_filter: true, | ||
can_sort: true | ||
}, | ||
"degree.name": { | ||
can_filter: true, | ||
can_sort: true | ||
} | ||
}; | ||
|
||
const CommentController = { | ||
|
||
index: async req => { | ||
return await ModelController.index(req, { | ||
Model: Comment, | ||
fields | ||
}); | ||
}, | ||
|
||
view: async req => { | ||
return await ModelController.view(req, { | ||
Model: Comment, | ||
fields | ||
}) | ||
}, | ||
|
||
post: async req => { | ||
const comment = new Comment(req.body); | ||
return await comment.save(); | ||
} | ||
} | ||
|
||
module.exports = CommentController; |
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
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,19 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Attachment = mongoose.model('Attachment', { | ||
mimetype: { | ||
type: String | ||
}, | ||
uploader_id: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User' | ||
}, | ||
size: { | ||
type: String | ||
}, | ||
content: { | ||
type: String | ||
} | ||
}) | ||
|
||
module.exports = Attachment; |
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,20 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Comment = mongoose.model('Comment', { | ||
creator_id: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User' | ||
}, | ||
modifier_id: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User' | ||
}, | ||
content: { | ||
type: String | ||
}, | ||
attachments: [ | ||
{ type: mongoose.Schema.Types.ObjectId, ref: 'Attachment' } | ||
] | ||
}) | ||
|
||
module.exports = Comment; |
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