Skip to content

Instantly share code, notes, and snippets.

@e06widu
Created June 29, 2020 17:53
Show Gist options
  • Save e06widu/7a1f6d99675cfb6f6fb870117f4565d9 to your computer and use it in GitHub Desktop.
Save e06widu/7a1f6d99675cfb6f6fb870117f4565d9 to your computer and use it in GitHub Desktop.
Processed result using created functions
import { AzureFunction, Context, HttpRequest } from '@azure/functions';
import * as Joi from '@hapi/joi';
import { ProcessorResponse } from '../utils';
const httpTrigger: AzureFunction = async (context: Context, req: HttpRequest): Promise<void> => {
context.log('HTTP trigger function processed a request.');
const userSchema = Joi.object({
FirstName: Joi.string().alphanum().max(20).required(),
LastName: Joi.string().alphanum().min(1).max(20),
BirthYear: Joi.number().integer().min(1900).max(2013)
});
const name = (req.query.name || (req.body && req.body.name));
try {
const value = await userSchema.validateAsync(req.body);
// context.res = {
// status: 200,
// body: {
// message : 'User validated'
// }
// };
context.res = ProcessorResponse.createValidResponse('User validated', 200);
} catch (error) {
// context.res = {
// status: 400,
// body: {
// message : error.message
// }
// };
context.log(error);
context.res = ProcessorResponse.createInvalidResponse(error.message, 400);
}
};
export default httpTrigger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment