Update casing for services and controllers directories.

This commit is contained in:
Aaron William Po
2023-12-10 18:15:35 -05:00
parent fd641c36ab
commit 8b0d182cb3
184 changed files with 195 additions and 190 deletions

View File

@@ -0,0 +1,34 @@
import ServerError from '@/config/util/ServerError';
import addBeerImageToDB from '@/services/images/beer-image/addBeerImageToDB';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
import { NextApiResponse } from 'next';
import { z } from 'zod';
import { UploadImagesRequest } from '../types';
// eslint-disable-next-line import/prefer-default-export
export const processBeerImageData = async (
req: UploadImagesRequest,
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
) => {
const { files, user, body } = req;
if (!files || !files.length) {
throw new ServerError('No images uploaded', 400);
}
const beerImages = await addBeerImageToDB({
alt: body.alt,
caption: body.caption,
beerPostId: req.query.id,
userId: user!.id,
files,
});
res.status(200).json({
success: true,
message: `Successfully uploaded ${beerImages.length} image${
beerImages.length > 1 ? 's' : ''
}`,
statusCode: 200,
});
};