Hash my url (#2484)

* disposable link model added

* disposable model updated

* added disposable slug availability page

* added disposable book page

* added disposable slug hook

* added disposable link booking flow

* updated schema

* checktype fix

* added checkfix and schema generated

* create link API added

* added one time link view on event type list

* adjusted schema

* fixed disposable visual indicator

* expired check and visual indicator added

* updated slug for disposable event type

* revised schema

* WIP

* revert desc

* revert --WIP

* rework based on change of plans

* further adjustments

* added eventtype option for hashed link

* added refresh and delete on update

* fixed update call conditions

* cleanup

* code improvement

* clean up

* Potential fix for 404

* backward compat for booking page

* fixes regular booking for user and team

* typefix

* updated path for Booking import

* checkfix

* e2e wip

* link err fix

* workaround for banner issue in event type update-test

* added regenerate hash check

* fixed test according to new testID

Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: zomars <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-04-28 09:44:26 -06:00
1 parent 8e956893ca
commit 59a1db9068
14 files changed
+627 -3

No files matched your search

+1
View File
@@ -133,6 +133,7 @@ const loggedInViewerRouter = createProtectedRouter()
currency: true,
position: true,
successRedirectUrl: true,
hashedLink: true,
users: {
select: {
id: true,
+56 -2
View File
@@ -1,4 +1,6 @@
import { EventTypeCustomInput, MembershipRole, PeriodType, Prisma } from "@prisma/client";
import short from "short-uuid";
import { v5 as uuidv5 } from "uuid";
import { z } from "zod";
import {
@@ -89,6 +91,7 @@ const EventTypeUpdateInput = _EventTypeModel
}),
users: z.array(stringOrNumber).optional(),
schedule: z.number().optional(),
hashedLink: z.boolean(),
})
.partial()
.merge(
@@ -214,8 +217,17 @@ export const eventTypesRouter = createProtectedRouter()
.mutation("update", {
input: EventTypeUpdateInput.strict(),
async resolve({ ctx, input }) {
const { schedule, periodType, locations, destinationCalendar, customInputs, users, id, ...rest } =
input;
const {
schedule,
periodType,
locations,
destinationCalendar,
customInputs,
users,
id,
hashedLink,
...rest
} = input;
assertValidUrl(input.successRedirectUrl);
const data: Prisma.EventTypeUpdateInput = rest;
data.locations = locations ?? undefined;
@@ -250,6 +262,48 @@ export const eventTypesRouter = createProtectedRouter()
};
}
const connectedLink = await ctx.prisma.hashedLink.findFirst({
where: {
eventTypeId: input.id,
},
select: {
id: true,
},
});
if (hashedLink) {
// check if hashed connection existed. If it did, do nothing. If it didn't, add a new connection
if (!connectedLink) {
const translator = short();
const seed = `${input.eventName}:${input.id}:${new Date().getTime()}`;
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
// create a hashed link
await ctx.prisma.hashedLink.upsert({
where: {
eventTypeId: input.id,
},
update: {
link: uid,
},
create: {
link: uid,
eventType: {
connect: { id: input.id },
},
},
});
}
} else {
// check if hashed connection exists. If it does, disconnect
if (connectedLink) {
await ctx.prisma.hashedLink.delete({
where: {
eventTypeId: input.id,
},
});
}
}
const eventType = await ctx.prisma.eventType.update({
where: { id },
data,