mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
40 lines
1001 B
TypeScript
40 lines
1001 B
TypeScript
import DBClient from '@/prisma/DBClient';
|
|
import { BeerImage } from '@prisma/client';
|
|
import { z } from 'zod';
|
|
import ImageMetadataValidationSchema from '../schema/ImageSchema/ImageMetadataValidationSchema';
|
|
|
|
interface ProcessImageDataArgs {
|
|
files: Express.Multer.File[];
|
|
alt: z.infer<typeof ImageMetadataValidationSchema>['alt'];
|
|
caption: z.infer<typeof ImageMetadataValidationSchema>['caption'];
|
|
beerPostId: string;
|
|
userId: string;
|
|
}
|
|
|
|
const addBeerImageToDB = ({
|
|
alt,
|
|
caption,
|
|
files,
|
|
beerPostId,
|
|
userId,
|
|
}: ProcessImageDataArgs) => {
|
|
const beerImagePromises: Promise<BeerImage>[] = [];
|
|
files.forEach((file) => {
|
|
beerImagePromises.push(
|
|
DBClient.instance.beerImage.create({
|
|
data: {
|
|
alt,
|
|
caption,
|
|
postedBy: { connect: { id: userId } },
|
|
beerPost: { connect: { id: beerPostId } },
|
|
path: file.path,
|
|
},
|
|
}),
|
|
);
|
|
});
|
|
|
|
return Promise.all(beerImagePromises);
|
|
};
|
|
|
|
export default addBeerImageToDB;
|