-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change
validateContained
to async funtion
- Loading branch information
1 parent
0aab652
commit 0a30cd1
Showing
3 changed files
with
28 additions
and
21 deletions.
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
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 |
---|---|---|
@@ -1,31 +1,38 @@ | ||
const mongodb = require('../../models/mongodb'); | ||
const _ = require('lodash'); | ||
|
||
module.exports = (resourceItem, index) => { | ||
let resourceType = _.get(resourceItem, "resourceType", false); | ||
if (!resourceType) { | ||
return { | ||
status: false, | ||
message: `Missing resourceType in contained[${index}]` | ||
}; | ||
} | ||
if (mongodb[resourceType]) { | ||
let resourceToMongoModel = new mongodb[resourceType](resourceItem); | ||
let validation = resourceToMongoModel.validateSync(); | ||
if (_.get(validation,"errors")) { | ||
module.exports = async (resourceItem, index) => { | ||
try { | ||
let resourceType = _.get(resourceItem, "resourceType", false); | ||
if (!resourceType) { | ||
return { | ||
status: false, | ||
message: validation.message | ||
message: `Missing resourceType in contained[${index}]` | ||
}; | ||
} | ||
if (mongodb[resourceType]) { | ||
let resourceToMongoModel = new mongodb[resourceType](resourceItem); | ||
await resourceToMongoModel.validate(); | ||
return { | ||
status: true, | ||
message: "success" | ||
}; | ||
} else { | ||
return { | ||
status: false, | ||
message: `Burni not support this resource type. ${resourceType}` | ||
}; | ||
} | ||
} catch(e) { | ||
if (_.get(e,"errors")) { | ||
return { | ||
status: false, | ||
message: e.message | ||
}; | ||
} | ||
return { | ||
status: true, | ||
message: "success" | ||
}; | ||
} else { | ||
return { | ||
status: false, | ||
message: `Burni not support this resource type. ${resourceType}` | ||
message: e | ||
}; | ||
} | ||
}; |