Files
internship_node/day11/resolvers/create/createImage.js
T
ryanwong a07577bffa day 11
2022-02-06 22:15:10 -05:00

39 lines
1001 B
JavaScript
Executable File

"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* image Resolve Add
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { url,
caption } = args;
const v = new Validator({ url: args.url}, { url: "required" });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.image.insert({ url,
caption },{returnAllFields: true});
} catch (error) {
console.log('create_image -> error', error);
return new ApolloError('InternalServerError');
}
};