mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-05 18:09:04 +00:00
refactor image services
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import ServerError from '@/config/util/ServerError';
|
||||
import addBeerImageToDB from '@/services/images/beer-image/addBeerImageToDB';
|
||||
import {
|
||||
addBeerImagesToDB,
|
||||
deleteBeerImageFromDBAndStorage,
|
||||
} from '@/services/images/beer-image';
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { z } from 'zod';
|
||||
import { UploadImagesRequest } from '../types';
|
||||
import { DeleteImageRequest, UploadImagesRequest } from '../types';
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export const processBeerImageData = async (
|
||||
@@ -16,11 +19,10 @@ export const processBeerImageData = async (
|
||||
throw new ServerError('No images uploaded', 400);
|
||||
}
|
||||
|
||||
const beerImages = await addBeerImageToDB({
|
||||
alt: body.alt,
|
||||
caption: body.caption,
|
||||
const beerImages = await addBeerImagesToDB({
|
||||
beerPostId: req.query.id,
|
||||
userId: user!.id,
|
||||
body,
|
||||
files,
|
||||
});
|
||||
|
||||
@@ -32,3 +34,18 @@ export const processBeerImageData = async (
|
||||
statusCode: 200,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteBeerImageData = async (
|
||||
req: DeleteImageRequest,
|
||||
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
|
||||
) => {
|
||||
const { id } = req.query;
|
||||
|
||||
await deleteBeerImageFromDBAndStorage({ beerImageId: id });
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: `Successfully deleted image with id ${id}`,
|
||||
statusCode: 200,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user