function validationMiddlware(req) { return Joi.validate( req.payload.pattern.message, Joi.object() .keys({ from: Joi.string().required(), to: Joi.string().required(), subject: Joi.string().required(), text: Joi.string().optional(), html: Joi.string().optional(), bcc: Joi.string().optional(), cc: Joi.string().optional() }) .required() ) }
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static remove(topic) { return { topic, cmd: 'remove', collection: Joi.string().required(), query: Joi.object().required() } }
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static find(topic) { return { topic, cmd: 'find', collection: Joi.string().required(), query: Joi.object().required(), options: Joi.object() .keys({ fields: Joi.alternatives().try(Joi.object(), Joi.array()), orderBy: Joi.alternatives().try(Joi.object(), Joi.array(), Joi.string()), offset: Joi.number().integer(), limit: Joi.number().integer() }) .default({}) } }
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static count(topic) { return { topic, cmd: 'count', collection: Joi.string().required(), query: Joi.alternatives() .try(Joi.object(), Joi.string()) .required() } }
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static updateById(topic) { return { topic, cmd: 'updateById', collection: Joi.string().required(), data: Joi.object().required(), id: Joi.alternatives() .try(Joi.number(), Joi.string()) .required() } }
it('should assign name to Anon if one was not given', async () => { const joiSchema = object().keys({ a: string(), b: number().integer() }); Joi2GQL.type(joiSchema).name.should.equal('Anon'); });
Joi.object().keys({ id : Joi.number().integer(), firstname : Joi.string().max(128).optional(), lastname : Joi.string().max(128).optional(), created_at : Joi.date().default(() => moment().format(), 'date created'), updated_at : Joi.date().default(() => moment().format(), 'date updated'), })
it('should properly create a GraphQL data type and support int scalar types', async () => { const joiSchema = object().keys({ a: number().integer() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.equal( GraphQLInt ); });
it('should properly create a GraphQL data type and support boolean scalar types', async () => { const joiSchema = object().keys({ a: boolean() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.equal( GraphQLBoolean ); });
it('should properly create a GraphQL data type and support complex required fields', async () => { const joiSchema = object().keys({ a: number().integer().required() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.deep.equal( new GraphQLNonNull(GraphQLInt) ); });
it('should properly create a GraphQL data type and support string scalar types', async () => { const joiSchema = object().keys({ a: string() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.equal( GraphQLString ); });
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static exists(topic) { return { topic, cmd: 'exists', collection: Joi.string().required(), query: Joi.object().required() } }
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static replaceById(topic) { return { topic, cmd: 'replaceById', collection: Joi.string().required(), data: Joi.object().required(), id: Joi.alternatives() .try(Joi.number(), Joi.string()) .required() } }