chore: Update api service type directories to maintain consistency

This commit is contained in:
Aaron William Po
2023-07-07 23:23:04 -04:00
parent ee47f99f8a
commit 5292c47a2a
69 changed files with 99 additions and 99 deletions

View File

@@ -0,0 +1,14 @@
import { z } from 'zod';
const BreweryPostMapQueryResult = z.object({
location: z.object({
coordinates: z.array(z.number()),
city: z.string(),
country: z.string().nullable(),
stateOrProvince: z.string().nullable(),
}),
id: z.string(),
name: z.string(),
});
export default BreweryPostMapQueryResult;

View File

@@ -0,0 +1,22 @@
import { z } from 'zod';
const BreweryPostQueryResult = z.object({
id: z.string(),
name: z.string(),
description: z.string(),
location: z.object({
city: z.string(),
address: z.string(),
coordinates: z.array(z.number()),
country: z.string().nullable(),
stateOrProvince: z.string().nullable(),
}),
postedBy: z.object({ id: z.string(), username: z.string() }),
breweryImages: z.array(
z.object({ path: z.string(), caption: z.string(), id: z.string(), alt: z.string() }),
),
createdAt: z.coerce.date(),
dateEstablished: z.coerce.date(),
});
export default BreweryPostQueryResult;

View File

@@ -0,0 +1,55 @@
import { isPast } from 'date-fns';
import { z } from 'zod';
const CreateBreweryPostSchema = z.object({
name: z
.string({
required_error: 'Brewery name is required.',
invalid_type_error: 'Brewery name must be a string.',
})
.min(1, { message: 'Brewery name is required.' })
.max(100, { message: 'Brewery name is too long.' }),
description: z
.string({
required_error: 'Description is required.',
invalid_type_error: 'Description must be a string.',
})
.min(1, { message: 'Description is required.' })
.max(500, { message: 'Description is too long.' }),
address: z
.string({
required_error: 'Address is required.',
invalid_type_error: 'Address must be a string.',
})
.min(1, { message: 'Address is required.' })
.max(100, { message: 'Address is too long.' }),
city: z
.string({
required_error: 'City is required.',
invalid_type_error: 'City must be a string.',
})
.min(1, { message: 'City is required.' })
.max(100, { message: 'City is too long.' }),
region: z
.string({ invalid_type_error: 'region must be a string.' })
.min(1, { message: 'region is required.' })
.max(100, { message: 'region is too long.' })
.optional(),
country: z
.string({ invalid_type_error: 'Country must be a string.' })
.max(100, { message: 'Country is too long.' })
.optional(),
dateEstablished: z.coerce
.date({
required_error: 'Date established is required.',
invalid_type_error: 'Date established must be a date string.',
})
.refine((val) => !Number.isNaN(val.toString()), { message: 'Date is invalid.' })
.refine((val) => isPast(new Date(val)), { message: 'Date must be in the past.' }),
});
export default CreateBreweryPostSchema;

View File

@@ -0,0 +1,13 @@
import { z } from 'zod';
import CreateBreweryPostSchema from './CreateBreweryPostSchema';
const EditBreweryPostValidationSchema = CreateBreweryPostSchema.extend({
id: z.string().cuid(),
}).omit({
address: true,
city: true,
region: true,
country: true,
});
export default EditBreweryPostValidationSchema;