Feat: add create brewery post, brewery image upload

Add address autocomplete, using MapBox
This commit is contained in:
Aaron William Po
2023-06-10 22:09:51 -04:00
parent 140abaa5a1
commit aa994f0067
19 changed files with 855 additions and 39 deletions

View File

@@ -0,0 +1,39 @@
import DBClient from '@/prisma/DBClient';
import { BreweryImage } from '@prisma/client';
import { z } from 'zod';
import ImageMetadataValidationSchema from '../types/ImageSchema/ImageMetadataValidationSchema';
interface ProcessImageDataArgs {
files: Express.Multer.File[];
alt: z.infer<typeof ImageMetadataValidationSchema>['alt'];
caption: z.infer<typeof ImageMetadataValidationSchema>['caption'];
breweryPostId: string;
userId: string;
}
const addBreweryImageToDB = ({
alt,
caption,
files,
breweryPostId,
userId,
}: ProcessImageDataArgs) => {
const breweryImagePromises: Promise<BreweryImage>[] = [];
files.forEach((file) => {
breweryImagePromises.push(
DBClient.instance.breweryImage.create({
data: {
alt,
caption,
postedBy: { connect: { id: userId } },
breweryPost: { connect: { id: breweryPostId } },
path: file.path,
},
}),
);
});
return Promise.all(breweryImagePromises);
};
export default addBreweryImageToDB;