Files
node_learning_module_1/day11/resolvers/update/updateCode.js
T

33 lines
961 B
JavaScript
Raw Normal View History

2022-02-06 22:15:10 -05:00
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* code Resolve Update
* @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 { code } = args;
const v = new Validator({ code: args.code}, { code: "required" });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.code.edit({ code }, args.id);
} catch (error) {
console.log('update_code -> error', error);
return new ApolloError('InternalServerError');
}
};