@@ -52,36 +52,40 @@ async function _getChallengeAttachment (challengeId, attachmentId) {
52
52
/**
53
53
* Create attachment.
54
54
* @param {String } challengeId the challenge id
55
- * @param {Object } attachment the attachment to created
55
+ * @param {Array } attachments the attachments to be created
56
56
* @returns {Object } the created attachment
57
57
*/
58
- async function createAttachment ( currentUser , challengeId , attachment ) {
58
+ async function createAttachment ( currentUser , challengeId , attachments ) {
59
59
const challenge = await helper . getById ( 'Challenge' , challengeId )
60
60
await helper . ensureUserCanModifyChallenge ( currentUser , challenge )
61
- validateUrl ( attachment . url )
62
- const attachmentObject = { id : uuid ( ) , challengeId, ...attachment }
63
- const ret = await helper . create ( 'Attachment' , attachmentObject )
61
+ const newAttachments = [ ]
62
+ for ( const attachment of attachments ) {
63
+ validateUrl ( attachment . url )
64
+ const attachmentObject = { id : uuid ( ) , challengeId, ...attachment }
65
+ const newAttachment = await helper . create ( 'Attachment' , attachmentObject )
66
+ await helper . postBusEvent ( constants . Topics . ChallengeAttachmentCreated , ret )
67
+ newAttachments . push ( newAttachment )
68
+ }
64
69
// update challenge object
65
70
await challengeService . partiallyUpdateChallenge ( currentUser , challengeId , {
66
71
attachments : [
67
72
..._ . get ( challenge , 'attachments' , [ ] ) ,
68
- ret
73
+ ... newAttachments
69
74
]
70
75
} )
71
76
// post bus event
72
- await helper . postBusEvent ( constants . Topics . ChallengeAttachmentCreated , ret )
73
- return ret
77
+ return newAttachments
74
78
}
75
79
76
80
createAttachment . schema = {
77
81
currentUser : Joi . any ( ) ,
78
82
challengeId : Joi . id ( ) ,
79
- attachment : Joi . object ( ) . keys ( {
83
+ attachments : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
80
84
name : Joi . string ( ) . required ( ) ,
81
85
url : Joi . string ( ) . uri ( ) . required ( ) ,
82
86
fileSize : Joi . fileSize ( ) ,
83
87
description : Joi . string ( )
84
- } ) . required ( )
88
+ } ) ) . required ( ) . min ( 1 )
85
89
}
86
90
87
91
/**
0 commit comments