mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
chore: Update api service type directories to maintain consistency
This commit is contained in:
14
src/services/BreweryPost/schema/BreweryPostMapQueryResult.ts
Normal file
14
src/services/BreweryPost/schema/BreweryPostMapQueryResult.ts
Normal 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;
|
||||
22
src/services/BreweryPost/schema/BreweryPostQueryResult.ts
Normal file
22
src/services/BreweryPost/schema/BreweryPostQueryResult.ts
Normal 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;
|
||||
55
src/services/BreweryPost/schema/CreateBreweryPostSchema.ts
Normal file
55
src/services/BreweryPost/schema/CreateBreweryPostSchema.ts
Normal 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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user