@ordinatio/scheduling-api 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -0
- package/README.md +9 -5
- package/dist/agent/index.js +1861 -79
- package/dist/agent/index.mjs +1861 -79
- package/dist/index.js +83 -43
- package/dist/index.mjs +83 -43
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3483,7 +3483,7 @@ async function createCoupon(request, { host }) {
|
|
|
3483
3483
|
async function getOwnedCoupon(db, id, organizationId) {
|
|
3484
3484
|
return db.couponCode.findFirst({
|
|
3485
3485
|
where: { id, organizationId },
|
|
3486
|
-
select: { id: true, code: true, usedCount: true, isActive: true }
|
|
3486
|
+
select: { id: true, code: true, usedCount: true, isActive: true, discountType: true, discountValue: true }
|
|
3487
3487
|
});
|
|
3488
3488
|
}
|
|
3489
3489
|
async function updateCoupon(request, { host, params }) {
|
|
@@ -3503,6 +3503,11 @@ async function updateCoupon(request, { host, params }) {
|
|
|
3503
3503
|
const validation = await parseBody(request, UpdateCouponCodeSchema);
|
|
3504
3504
|
if (!validation.success) return validation.response;
|
|
3505
3505
|
const input = validation.data;
|
|
3506
|
+
const finalType = input.discountType ?? existing.discountType;
|
|
3507
|
+
const finalValue = input.discountValue ?? Number(existing.discountValue);
|
|
3508
|
+
if (finalType === "PERCENTAGE" && finalValue > 100) {
|
|
3509
|
+
return Response.json({ error: "Percentage discount cannot exceed 100%" }, { status: 400 });
|
|
3510
|
+
}
|
|
3506
3511
|
const updated = await db.couponCode.update({
|
|
3507
3512
|
where: { id, organizationId },
|
|
3508
3513
|
data: {
|
|
@@ -3521,6 +3526,9 @@ async function updateCoupon(request, { host, params }) {
|
|
|
3521
3526
|
});
|
|
3522
3527
|
return Response.json({ coupon: updated });
|
|
3523
3528
|
} catch (error) {
|
|
3529
|
+
if (getErrorCode(error) === "P2002") {
|
|
3530
|
+
return Response.json({ error: "A coupon with this code already exists" }, { status: 409 });
|
|
3531
|
+
}
|
|
3524
3532
|
return Response.json({ error: getErrorMessage(error, "Failed to update coupon") }, { status: 500 });
|
|
3525
3533
|
}
|
|
3526
3534
|
}
|
|
@@ -3588,6 +3596,10 @@ async function createPackage(request, { host }) {
|
|
|
3588
3596
|
const validation = await parseBody(request, CreateServicePackageSchema);
|
|
3589
3597
|
if (!validation.success) return validation.response;
|
|
3590
3598
|
const input = validation.data;
|
|
3599
|
+
if (input.typeId) {
|
|
3600
|
+
const type = await db.appointmentType.findFirst({ where: { id: input.typeId, organizationId }, select: { id: true } });
|
|
3601
|
+
if (!type) return Response.json({ error: "Appointment type not found" }, { status: 404 });
|
|
3602
|
+
}
|
|
3591
3603
|
const pkg = await db.servicePackage.create({
|
|
3592
3604
|
data: {
|
|
3593
3605
|
name: input.name,
|
|
@@ -3639,6 +3651,10 @@ async function updatePackage(request, { host, params }) {
|
|
|
3639
3651
|
const validation = await parseBody(request, UpdateServicePackageSchema);
|
|
3640
3652
|
if (!validation.success) return validation.response;
|
|
3641
3653
|
const input = validation.data;
|
|
3654
|
+
if (input.typeId) {
|
|
3655
|
+
const type = await db.appointmentType.findFirst({ where: { id: input.typeId, organizationId }, select: { id: true } });
|
|
3656
|
+
if (!type) return Response.json({ error: "Appointment type not found" }, { status: 404 });
|
|
3657
|
+
}
|
|
3642
3658
|
const updated = await db.servicePackage.update({
|
|
3643
3659
|
where: { id, organizationId },
|
|
3644
3660
|
data: {
|
|
@@ -4140,46 +4156,54 @@ async function createRecurringSeries(request, { host }) {
|
|
|
4140
4156
|
{ status: 422 }
|
|
4141
4157
|
);
|
|
4142
4158
|
}
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4159
|
+
let series;
|
|
4160
|
+
try {
|
|
4161
|
+
series = await db.$transaction(async (tx) => {
|
|
4162
|
+
const created = await tx.recurringSeries.create({
|
|
4163
|
+
data: {
|
|
4164
|
+
organizationId,
|
|
4165
|
+
calendarId: input.calendarId,
|
|
4166
|
+
typeId: input.typeId,
|
|
4167
|
+
frequency: input.frequency,
|
|
4168
|
+
occurrences: slots.length,
|
|
4169
|
+
startTimeLocal: input.startTimeLocal,
|
|
4170
|
+
durationMins: apptType.duration,
|
|
4171
|
+
timezone: input.timezone,
|
|
4172
|
+
endsAt: endsAt ?? null,
|
|
4173
|
+
clientEmail: input.clientEmail,
|
|
4174
|
+
clientName: input.clientName,
|
|
4175
|
+
clientPhone: input.clientPhone ?? null,
|
|
4176
|
+
clientId,
|
|
4177
|
+
notes: input.notes ?? null,
|
|
4178
|
+
status: "ACTIVE"
|
|
4179
|
+
}
|
|
4180
|
+
});
|
|
4181
|
+
await tx.appointment.createMany({
|
|
4182
|
+
data: slots.map(({ startTime, endTime }, idx) => ({
|
|
4183
|
+
calendarId: input.calendarId,
|
|
4184
|
+
typeId: input.typeId,
|
|
4185
|
+
clientEmail: input.clientEmail,
|
|
4186
|
+
clientName: input.clientName,
|
|
4187
|
+
clientPhone: input.clientPhone ?? null,
|
|
4188
|
+
clientId,
|
|
4189
|
+
startTime,
|
|
4190
|
+
endTime,
|
|
4191
|
+
duration: apptType.duration,
|
|
4192
|
+
timezone: input.timezone,
|
|
4193
|
+
notes: input.notes ?? null,
|
|
4194
|
+
status: "CONFIRMED",
|
|
4195
|
+
recurringId: created.id,
|
|
4196
|
+
recurringIndex: idx + 1
|
|
4197
|
+
}))
|
|
4198
|
+
});
|
|
4199
|
+
return created;
|
|
4180
4200
|
});
|
|
4181
|
-
|
|
4182
|
-
|
|
4201
|
+
} catch (error) {
|
|
4202
|
+
if (getErrorCode(error) === "P2002") {
|
|
4203
|
+
return Response.json({ error: "One of the visits would start at exactly the same time as a booking already on this calendar. Nothing was saved." }, { status: 409 });
|
|
4204
|
+
}
|
|
4205
|
+
throw error;
|
|
4206
|
+
}
|
|
4183
4207
|
await host.activity.log(db, {
|
|
4184
4208
|
action: "scheduling.recurring_series_created",
|
|
4185
4209
|
description: `created ${slots.length}-occurrence ${input.frequency} series for ${input.clientName} (${input.clientEmail})`,
|
|
@@ -4898,7 +4922,7 @@ async function putCalendar(request, { host, params }) {
|
|
|
4898
4922
|
if (archived) await undoArchive(host, db, id, organizationId, existing.slug);
|
|
4899
4923
|
throw error;
|
|
4900
4924
|
}
|
|
4901
|
-
if (input.slotGranularityMinutes !== void 0) await host.availabilityCache.invalidate(id);
|
|
4925
|
+
if (input.slotGranularityMinutes !== void 0 || input.timezone !== void 0) await host.availabilityCache.invalidate(id);
|
|
4902
4926
|
if (archiving) await releaseCalendarSlugIfStillInactive(host, db, id, organizationId, existing.slug);
|
|
4903
4927
|
await bustCalendarCachesOnUpdate(host, organizationId, existing.slug, input, id);
|
|
4904
4928
|
await host.activity.log(db, {
|
|
@@ -5141,6 +5165,15 @@ async function requireOwnedVisibleCalendar(staff, calendarId) {
|
|
|
5141
5165
|
return calendar ?? NOT_FOUND8();
|
|
5142
5166
|
}
|
|
5143
5167
|
|
|
5168
|
+
// src/availability/clear-availability-cache.ts
|
|
5169
|
+
async function clearAvailabilityCache(host, calendarId) {
|
|
5170
|
+
try {
|
|
5171
|
+
await host.availabilityCache.invalidate(calendarId);
|
|
5172
|
+
} catch (error) {
|
|
5173
|
+
console.warn("[availability-cache-clear-failed]", calendarId, error);
|
|
5174
|
+
}
|
|
5175
|
+
}
|
|
5176
|
+
|
|
5144
5177
|
// src/availability/validate-weekly-rules.ts
|
|
5145
5178
|
function validateWeeklyRules(rules) {
|
|
5146
5179
|
for (const rule of rules) {
|
|
@@ -5210,6 +5243,7 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
5210
5243
|
const validationError = validateWeeklyRules(rules);
|
|
5211
5244
|
if (validationError) return Response.json({ error: validationError }, { status: 400 });
|
|
5212
5245
|
const created = await (0, import_scheduling39.setWeeklyAvailability)(db, calendarId, rules);
|
|
5246
|
+
await clearAvailabilityCache(host, calendarId);
|
|
5213
5247
|
const activeDays = rules.map((r) => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][r.dayOfWeek]).join(", ");
|
|
5214
5248
|
await host.activity.log(db, {
|
|
5215
5249
|
action: "scheduling.availability_updated",
|
|
@@ -5284,6 +5318,7 @@ async function addOverride(request, { host, params }) {
|
|
|
5284
5318
|
endTime: body.endTime
|
|
5285
5319
|
});
|
|
5286
5320
|
}
|
|
5321
|
+
await clearAvailabilityCache(host, calendarId);
|
|
5287
5322
|
let overlapWarning;
|
|
5288
5323
|
if (isBlockedFlag && body.startTime && body.endTime) {
|
|
5289
5324
|
const dateStr = body.date.split("T")[0];
|
|
@@ -5330,6 +5365,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
5330
5365
|
const { ruleId } = await request.json();
|
|
5331
5366
|
if (!ruleId) return Response.json({ error: "ruleId is required" }, { status: 400 });
|
|
5332
5367
|
const deletedRule = await (0, import_scheduling41.removeDateOverride)(db, calendarId, ruleId);
|
|
5368
|
+
await clearAvailabilityCache(host, calendarId);
|
|
5333
5369
|
const deletedIsTimeBlock = deletedRule?.isBlocked && !(deletedRule.startTime === "00:00" && deletedRule.endTime === "00:00");
|
|
5334
5370
|
await host.activity.log(db, {
|
|
5335
5371
|
action: "scheduling.date_override_removed",
|
|
@@ -5394,7 +5430,7 @@ async function createTemplate(request, { host }) {
|
|
|
5394
5430
|
if (input.channel === "SMS" && input.subject) {
|
|
5395
5431
|
return Response.json({ error: "SMS templates cannot have a subject" }, { status: 400 });
|
|
5396
5432
|
}
|
|
5397
|
-
if (input.channel === "EMAIL" && !input.subject
|
|
5433
|
+
if (input.channel === "EMAIL" && !stripHtml(input.subject).trim()) {
|
|
5398
5434
|
return Response.json({ error: "EMAIL templates require a subject" }, { status: 400 });
|
|
5399
5435
|
}
|
|
5400
5436
|
const template = await (0, import_scheduling42.createNotificationTemplate)(db, organizationId, {
|
|
@@ -6563,7 +6599,7 @@ async function resolveBookingContext(host, cors, body) {
|
|
|
6563
6599
|
if (body.packagePurchaseId) {
|
|
6564
6600
|
const purchase = await db.packagePurchase.findFirst({
|
|
6565
6601
|
where: { id: body.packagePurchaseId, organizationId: orgId },
|
|
6566
|
-
select: { id: true, status: true, expiresAt: true, sessionsUsed: true, sessionsTotal: true, clientEmail: true }
|
|
6602
|
+
select: { id: true, status: true, expiresAt: true, sessionsUsed: true, sessionsTotal: true, clientEmail: true, package: { select: { typeId: true } } }
|
|
6567
6603
|
});
|
|
6568
6604
|
if (!purchase) return fail(404, { error: "Package purchase not found" });
|
|
6569
6605
|
if (purchase.status !== "ACTIVE") {
|
|
@@ -6574,6 +6610,10 @@ async function resolveBookingContext(host, cors, body) {
|
|
|
6574
6610
|
if (purchase.clientEmail.toLowerCase() !== body.clientEmail.toLowerCase()) {
|
|
6575
6611
|
return fail(403, { error: "Package does not belong to this client" });
|
|
6576
6612
|
}
|
|
6613
|
+
const packageTypeId = purchase.package?.typeId ?? null;
|
|
6614
|
+
if (packageTypeId && packageTypeId !== body.typeId) {
|
|
6615
|
+
return fail(409, { error: "This package cannot be used for this appointment type" });
|
|
6616
|
+
}
|
|
6577
6617
|
}
|
|
6578
6618
|
return { ok: true, orgId, db, calendar, appointmentType, noShowApprovalOverride };
|
|
6579
6619
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -3001,7 +3001,7 @@ async function createCoupon(request, { host }) {
|
|
|
3001
3001
|
async function getOwnedCoupon(db, id, organizationId) {
|
|
3002
3002
|
return db.couponCode.findFirst({
|
|
3003
3003
|
where: { id, organizationId },
|
|
3004
|
-
select: { id: true, code: true, usedCount: true, isActive: true }
|
|
3004
|
+
select: { id: true, code: true, usedCount: true, isActive: true, discountType: true, discountValue: true }
|
|
3005
3005
|
});
|
|
3006
3006
|
}
|
|
3007
3007
|
async function updateCoupon(request, { host, params }) {
|
|
@@ -3021,6 +3021,11 @@ async function updateCoupon(request, { host, params }) {
|
|
|
3021
3021
|
const validation = await parseBody(request, UpdateCouponCodeSchema);
|
|
3022
3022
|
if (!validation.success) return validation.response;
|
|
3023
3023
|
const input = validation.data;
|
|
3024
|
+
const finalType = input.discountType ?? existing.discountType;
|
|
3025
|
+
const finalValue = input.discountValue ?? Number(existing.discountValue);
|
|
3026
|
+
if (finalType === "PERCENTAGE" && finalValue > 100) {
|
|
3027
|
+
return Response.json({ error: "Percentage discount cannot exceed 100%" }, { status: 400 });
|
|
3028
|
+
}
|
|
3024
3029
|
const updated = await db.couponCode.update({
|
|
3025
3030
|
where: { id, organizationId },
|
|
3026
3031
|
data: {
|
|
@@ -3039,6 +3044,9 @@ async function updateCoupon(request, { host, params }) {
|
|
|
3039
3044
|
});
|
|
3040
3045
|
return Response.json({ coupon: updated });
|
|
3041
3046
|
} catch (error) {
|
|
3047
|
+
if (getErrorCode(error) === "P2002") {
|
|
3048
|
+
return Response.json({ error: "A coupon with this code already exists" }, { status: 409 });
|
|
3049
|
+
}
|
|
3042
3050
|
return Response.json({ error: getErrorMessage(error, "Failed to update coupon") }, { status: 500 });
|
|
3043
3051
|
}
|
|
3044
3052
|
}
|
|
@@ -3106,6 +3114,10 @@ async function createPackage(request, { host }) {
|
|
|
3106
3114
|
const validation = await parseBody(request, CreateServicePackageSchema);
|
|
3107
3115
|
if (!validation.success) return validation.response;
|
|
3108
3116
|
const input = validation.data;
|
|
3117
|
+
if (input.typeId) {
|
|
3118
|
+
const type = await db.appointmentType.findFirst({ where: { id: input.typeId, organizationId }, select: { id: true } });
|
|
3119
|
+
if (!type) return Response.json({ error: "Appointment type not found" }, { status: 404 });
|
|
3120
|
+
}
|
|
3109
3121
|
const pkg = await db.servicePackage.create({
|
|
3110
3122
|
data: {
|
|
3111
3123
|
name: input.name,
|
|
@@ -3157,6 +3169,10 @@ async function updatePackage(request, { host, params }) {
|
|
|
3157
3169
|
const validation = await parseBody(request, UpdateServicePackageSchema);
|
|
3158
3170
|
if (!validation.success) return validation.response;
|
|
3159
3171
|
const input = validation.data;
|
|
3172
|
+
if (input.typeId) {
|
|
3173
|
+
const type = await db.appointmentType.findFirst({ where: { id: input.typeId, organizationId }, select: { id: true } });
|
|
3174
|
+
if (!type) return Response.json({ error: "Appointment type not found" }, { status: 404 });
|
|
3175
|
+
}
|
|
3160
3176
|
const updated = await db.servicePackage.update({
|
|
3161
3177
|
where: { id, organizationId },
|
|
3162
3178
|
data: {
|
|
@@ -3663,46 +3679,54 @@ async function createRecurringSeries(request, { host }) {
|
|
|
3663
3679
|
{ status: 422 }
|
|
3664
3680
|
);
|
|
3665
3681
|
}
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3682
|
+
let series;
|
|
3683
|
+
try {
|
|
3684
|
+
series = await db.$transaction(async (tx) => {
|
|
3685
|
+
const created = await tx.recurringSeries.create({
|
|
3686
|
+
data: {
|
|
3687
|
+
organizationId,
|
|
3688
|
+
calendarId: input.calendarId,
|
|
3689
|
+
typeId: input.typeId,
|
|
3690
|
+
frequency: input.frequency,
|
|
3691
|
+
occurrences: slots.length,
|
|
3692
|
+
startTimeLocal: input.startTimeLocal,
|
|
3693
|
+
durationMins: apptType.duration,
|
|
3694
|
+
timezone: input.timezone,
|
|
3695
|
+
endsAt: endsAt ?? null,
|
|
3696
|
+
clientEmail: input.clientEmail,
|
|
3697
|
+
clientName: input.clientName,
|
|
3698
|
+
clientPhone: input.clientPhone ?? null,
|
|
3699
|
+
clientId,
|
|
3700
|
+
notes: input.notes ?? null,
|
|
3701
|
+
status: "ACTIVE"
|
|
3702
|
+
}
|
|
3703
|
+
});
|
|
3704
|
+
await tx.appointment.createMany({
|
|
3705
|
+
data: slots.map(({ startTime, endTime }, idx) => ({
|
|
3706
|
+
calendarId: input.calendarId,
|
|
3707
|
+
typeId: input.typeId,
|
|
3708
|
+
clientEmail: input.clientEmail,
|
|
3709
|
+
clientName: input.clientName,
|
|
3710
|
+
clientPhone: input.clientPhone ?? null,
|
|
3711
|
+
clientId,
|
|
3712
|
+
startTime,
|
|
3713
|
+
endTime,
|
|
3714
|
+
duration: apptType.duration,
|
|
3715
|
+
timezone: input.timezone,
|
|
3716
|
+
notes: input.notes ?? null,
|
|
3717
|
+
status: "CONFIRMED",
|
|
3718
|
+
recurringId: created.id,
|
|
3719
|
+
recurringIndex: idx + 1
|
|
3720
|
+
}))
|
|
3721
|
+
});
|
|
3722
|
+
return created;
|
|
3703
3723
|
});
|
|
3704
|
-
|
|
3705
|
-
|
|
3724
|
+
} catch (error) {
|
|
3725
|
+
if (getErrorCode(error) === "P2002") {
|
|
3726
|
+
return Response.json({ error: "One of the visits would start at exactly the same time as a booking already on this calendar. Nothing was saved." }, { status: 409 });
|
|
3727
|
+
}
|
|
3728
|
+
throw error;
|
|
3729
|
+
}
|
|
3706
3730
|
await host.activity.log(db, {
|
|
3707
3731
|
action: "scheduling.recurring_series_created",
|
|
3708
3732
|
description: `created ${slots.length}-occurrence ${input.frequency} series for ${input.clientName} (${input.clientEmail})`,
|
|
@@ -4421,7 +4445,7 @@ async function putCalendar(request, { host, params }) {
|
|
|
4421
4445
|
if (archived) await undoArchive(host, db, id, organizationId, existing.slug);
|
|
4422
4446
|
throw error;
|
|
4423
4447
|
}
|
|
4424
|
-
if (input.slotGranularityMinutes !== void 0) await host.availabilityCache.invalidate(id);
|
|
4448
|
+
if (input.slotGranularityMinutes !== void 0 || input.timezone !== void 0) await host.availabilityCache.invalidate(id);
|
|
4425
4449
|
if (archiving) await releaseCalendarSlugIfStillInactive(host, db, id, organizationId, existing.slug);
|
|
4426
4450
|
await bustCalendarCachesOnUpdate(host, organizationId, existing.slug, input, id);
|
|
4427
4451
|
await host.activity.log(db, {
|
|
@@ -4664,6 +4688,15 @@ async function requireOwnedVisibleCalendar(staff, calendarId) {
|
|
|
4664
4688
|
return calendar ?? NOT_FOUND8();
|
|
4665
4689
|
}
|
|
4666
4690
|
|
|
4691
|
+
// src/availability/clear-availability-cache.ts
|
|
4692
|
+
async function clearAvailabilityCache(host, calendarId) {
|
|
4693
|
+
try {
|
|
4694
|
+
await host.availabilityCache.invalidate(calendarId);
|
|
4695
|
+
} catch (error) {
|
|
4696
|
+
console.warn("[availability-cache-clear-failed]", calendarId, error);
|
|
4697
|
+
}
|
|
4698
|
+
}
|
|
4699
|
+
|
|
4667
4700
|
// src/availability/validate-weekly-rules.ts
|
|
4668
4701
|
function validateWeeklyRules(rules) {
|
|
4669
4702
|
for (const rule of rules) {
|
|
@@ -4733,6 +4766,7 @@ async function setWeeklyRules(request, { host, params }) {
|
|
|
4733
4766
|
const validationError = validateWeeklyRules(rules);
|
|
4734
4767
|
if (validationError) return Response.json({ error: validationError }, { status: 400 });
|
|
4735
4768
|
const created = await setWeeklyAvailability(db, calendarId, rules);
|
|
4769
|
+
await clearAvailabilityCache(host, calendarId);
|
|
4736
4770
|
const activeDays = rules.map((r) => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][r.dayOfWeek]).join(", ");
|
|
4737
4771
|
await host.activity.log(db, {
|
|
4738
4772
|
action: "scheduling.availability_updated",
|
|
@@ -4813,6 +4847,7 @@ async function addOverride(request, { host, params }) {
|
|
|
4813
4847
|
endTime: body.endTime
|
|
4814
4848
|
});
|
|
4815
4849
|
}
|
|
4850
|
+
await clearAvailabilityCache(host, calendarId);
|
|
4816
4851
|
let overlapWarning;
|
|
4817
4852
|
if (isBlockedFlag && body.startTime && body.endTime) {
|
|
4818
4853
|
const dateStr = body.date.split("T")[0];
|
|
@@ -4859,6 +4894,7 @@ async function removeOverride(request, { host, params }) {
|
|
|
4859
4894
|
const { ruleId } = await request.json();
|
|
4860
4895
|
if (!ruleId) return Response.json({ error: "ruleId is required" }, { status: 400 });
|
|
4861
4896
|
const deletedRule = await removeDateOverride(db, calendarId, ruleId);
|
|
4897
|
+
await clearAvailabilityCache(host, calendarId);
|
|
4862
4898
|
const deletedIsTimeBlock = deletedRule?.isBlocked && !(deletedRule.startTime === "00:00" && deletedRule.endTime === "00:00");
|
|
4863
4899
|
await host.activity.log(db, {
|
|
4864
4900
|
action: "scheduling.date_override_removed",
|
|
@@ -4923,7 +4959,7 @@ async function createTemplate(request, { host }) {
|
|
|
4923
4959
|
if (input.channel === "SMS" && input.subject) {
|
|
4924
4960
|
return Response.json({ error: "SMS templates cannot have a subject" }, { status: 400 });
|
|
4925
4961
|
}
|
|
4926
|
-
if (input.channel === "EMAIL" && !input.subject
|
|
4962
|
+
if (input.channel === "EMAIL" && !stripHtml(input.subject).trim()) {
|
|
4927
4963
|
return Response.json({ error: "EMAIL templates require a subject" }, { status: 400 });
|
|
4928
4964
|
}
|
|
4929
4965
|
const template = await createNotificationTemplate(db, organizationId, {
|
|
@@ -6107,7 +6143,7 @@ async function resolveBookingContext(host, cors, body) {
|
|
|
6107
6143
|
if (body.packagePurchaseId) {
|
|
6108
6144
|
const purchase = await db.packagePurchase.findFirst({
|
|
6109
6145
|
where: { id: body.packagePurchaseId, organizationId: orgId },
|
|
6110
|
-
select: { id: true, status: true, expiresAt: true, sessionsUsed: true, sessionsTotal: true, clientEmail: true }
|
|
6146
|
+
select: { id: true, status: true, expiresAt: true, sessionsUsed: true, sessionsTotal: true, clientEmail: true, package: { select: { typeId: true } } }
|
|
6111
6147
|
});
|
|
6112
6148
|
if (!purchase) return fail(404, { error: "Package purchase not found" });
|
|
6113
6149
|
if (purchase.status !== "ACTIVE") {
|
|
@@ -6118,6 +6154,10 @@ async function resolveBookingContext(host, cors, body) {
|
|
|
6118
6154
|
if (purchase.clientEmail.toLowerCase() !== body.clientEmail.toLowerCase()) {
|
|
6119
6155
|
return fail(403, { error: "Package does not belong to this client" });
|
|
6120
6156
|
}
|
|
6157
|
+
const packageTypeId = purchase.package?.typeId ?? null;
|
|
6158
|
+
if (packageTypeId && packageTypeId !== body.typeId) {
|
|
6159
|
+
return fail(409, { error: "This package cannot be used for this appointment type" });
|
|
6160
|
+
}
|
|
6121
6161
|
}
|
|
6122
6162
|
return { ok: true, orgId, db, calendar, appointmentType, noShowApprovalOverride };
|
|
6123
6163
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordinatio/scheduling-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "HTTP API for @ordinatio/scheduling. Every handler takes a Request and returns a Response.",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"sanitize-html": "^2.16.0"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@ordinatio/scheduling": "^0.
|
|
14
|
+
"@ordinatio/scheduling": "^0.6.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/sanitize-html": "^2.13.0",
|
|
18
18
|
"tsup": "^8.0.0",
|
|
19
19
|
"typescript": "5",
|
|
20
20
|
"vitest": "4.0.18",
|
|
21
|
-
"@ordinatio/scheduling": "0.
|
|
21
|
+
"@ordinatio/scheduling": "0.6.0"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">=22.0.0"
|