-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support updating venue profiles
- Loading branch information
Showing
9 changed files
with
365 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { generateBasePatchProfileModel } from "@/__test__/model/profiles/base/patch"; | ||
import { generateCoordsModel } from "@/__test__/model/profiles/coords"; | ||
import { PatchVenueModel } from "@/model/profiles/venues/patch"; | ||
import { faker } from "@faker-js/faker"; | ||
import { createId } from "@paralleldrive/cuid2"; | ||
import { ProfileType } from "@prisma/client"; | ||
|
||
export function generatePatchVenueModel( | ||
overrides: Partial<PatchVenueModel> = {} | ||
): PatchVenueModel { | ||
return { | ||
...generateBasePatchProfileModel(), | ||
type: ProfileType.venue, | ||
name: faker.helpers.maybe(() => faker.commerce.department()), | ||
coords: faker.helpers.maybe(() => generateCoordsModel()), | ||
permanentlyClosed: faker.helpers.maybe(() => | ||
faker.datatype.boolean({ probability: 0.2 }) | ||
), | ||
parentId: faker.helpers.maybe(() => | ||
faker.datatype.boolean() ? createId() : null | ||
), | ||
...overrides, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { BasePatchProfileDtoSchema } from "@/api/dto/profiles/base/patch"; | ||
import { CreateVenueDtoSchema } from "@/api/dto/profiles/venues/create"; | ||
import { registry } from "@/api/registry"; | ||
import z from "@/api/zod"; | ||
|
||
export type PatchVenueDto = z.infer<typeof PatchVenueDtoSchema>; | ||
export const PatchVenueDtoSchema = registry.register( | ||
"PatchVenueDto", | ||
BasePatchProfileDtoSchema.merge( | ||
z.object({ | ||
coords: CreateVenueDtoSchema.shape.coords.optional(), | ||
permanentlyClosed: | ||
CreateVenueDtoSchema.shape.permanentlyClosed.optional(), | ||
parentId: CreateVenueDtoSchema.shape.parentId.optional(), | ||
}) | ||
).refine( | ||
(dto) => { | ||
const dtoKeys = Object.keys(dto); | ||
const containsValidChanges = Object.keys(PatchVenueDtoSchema).some( | ||
(key) => dtoKeys.includes(key) | ||
); | ||
|
||
// HACK(FelixZY): Typescript does not allow a direct `return containsChanges` | ||
// as we are referencing `PatchVenueDtoSchema` in this function: | ||
// ``` | ||
// 'PatchVenueDtoSchema' implicitly has type 'any' because it does not | ||
// have a type annotation and is referenced directly or indirectly in its own initializer. | ||
// ts(7022) | ||
// ``` | ||
if (containsValidChanges) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
{ | ||
message: "At least one field modification is required", | ||
} | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
8ca0d50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
api – ./
api-git-main-dansdata.vercel.app
api-dansdata.vercel.app
api.dansdata.se