Skip to content

Commit 99097b8

Browse files
committed
Add support for multiple appointment bookings per user.
1 parent d71e6b7 commit 99097b8

9 files changed

+31
-27
lines changed

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
Welcome! Vanellus is the Kiebitzt Typescript library that provides
2-
all necessary functionality for building web applications based on
3-
the Kiebitz API and data models.
4-
5-
**This is still a work in progress.**
1+
Welcome! Vanellus is the official Kiebitz Typescript library that acts as an
2+
interface to the Kiebitz backend services and provides necessary functionality
3+
for building end-to-end encrypted applications with Kiebitz.
64

75
# Requirements
86

src/backend/appointments.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,20 @@ export class AppointmentsBackend extends JSONRPCBackend {
134134
async cancelAppointment(
135135
{
136136
providerID,
137+
slotID,
137138
id,
138139
signedTokenData,
139-
}: { providerID: string; id: string; signedTokenData: SignedData },
140+
}: {
141+
providerID: string
142+
slotID: string
143+
id: string
144+
signedTokenData: SignedData
145+
},
140146
keyPair: KeyPair
141147
) {
142148
return this.call<OK>(
143149
"cancelAppointment",
144-
{ providerID, id, signedTokenData },
150+
{ providerID, slotID, id, signedTokenData },
145151
keyPair
146152
)
147153
}

src/user/backup-data.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("User.backupData()", function () {
4646
deepEqual(newUser.contactData, user.contactData)
4747
deepEqual(newUser.tokenData, user.tokenData)
4848
deepEqual(newUser.queueData, user.queueData)
49-
deepEqual(newUser.acceptedAppointment, user.acceptedAppointment)
49+
deepEqual(newUser.acceptedAppointments, user.acceptedAppointments)
5050

5151
// we overwrite the secret
5252
newUser.initialize()

src/user/backup-data.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface CloudBackupData extends BackupData {
2727
tokenData: TokenData | null
2828
queueData: QueueData | null
2929
contactData: ContactData | null
30-
acceptedAppointment: AcceptedAppointment | null
30+
acceptedAppointments: AcceptedAppointment[]
3131
}
3232

3333
export interface BackupDataResult extends Result {
@@ -44,7 +44,7 @@ export async function backupData(
4444
tokenData: this.tokenData,
4545
queueData: this.queueData,
4646
contactData: this.contactData,
47-
acceptedAppointment: this.acceptedAppointment,
47+
acceptedAppointments: this.acceptedAppointments,
4848
}
4949

5050
const idAndKey = await deriveSecrets(base322buf(this.secret!), 32, 2)

src/user/book-appointment.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ describe("User.bookAppointment()", function () {
104104
if (cancelResult.status !== Status.Succeeded)
105105
throw new Error("cannot cancel appointment")
106106

107+
equal(user.appointments.length, 0)
108+
107109
apptsResult = await vp.appointments().get({
108110
from: formatDatetime(fromDate),
109111
to: formatDatetime(toDate),

src/user/book-appointment.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ export async function bookAppointment(
6363
}
6464

6565
// we store the information about the offer which we've accepted
66-
this.acceptedAppointment = acceptedAppointment
66+
const aa = this.acceptedAppointments
67+
aa.push(acceptedAppointment)
68+
this.acceptedAppointments = aa
6769

6870
return {
6971
status: Status.Succeeded,

src/user/cancel-appointment.ts

+6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ export async function cancelAppointment(
1919
const response = await this.backend.appointments.cancelAppointment(
2020
{
2121
id: acceptedAppointment.appointment.id,
22+
slotID: acceptedAppointment.booking.id,
2223
signedTokenData: this.tokenData!.signedToken,
2324
providerID: acceptedAppointment.provider.id,
2425
},
2526
this.tokenData!.keyPairs.signing
2627
)
2728

29+
// we remove the accepted appointment
30+
this.acceptedAppointments = this.acceptedAppointments.filter(
31+
(aa) => aa.booking.id !== acceptedAppointment.booking.id
32+
)
33+
2834
if (response !== "ok")
2935
return {
3036
status: Status.Failed,

src/user/index.ts

+5-15
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,13 @@ export class User extends Actor {
9090
this.set("contactData", contactData)
9191
}
9292

93-
public get verifiedAppointments(): ProviderAppointments[] | null {
94-
return this.get("verifiedAppointments")
93+
public get acceptedAppointments(): AcceptedAppointment[] {
94+
return this.get("acceptedAppointments") || []
9595
}
9696

97-
public set verifiedAppointments(
98-
verifiedAppointments: ProviderAppointments[] | null
97+
public set acceptedAppointments(
98+
acceptedAppointments: AcceptedAppointment[]
9999
) {
100-
this.set("verifiedAppointments", verifiedAppointments)
101-
}
102-
103-
public get acceptedAppointment(): AcceptedAppointment | null {
104-
return this.get("acceptedAppointment")
105-
}
106-
107-
public set acceptedAppointment(
108-
acceptedAppointment: AcceptedAppointment | null
109-
) {
110-
this.set("acceptedAppointment", acceptedAppointment)
100+
this.set("acceptedAppointments", acceptedAppointments)
111101
}
112102
}

src/user/restore-from-backup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function restoreFromBackup(
3535
this.tokenData = dd.tokenData
3636
this.queueData = dd.queueData
3737
this.contactData = dd.contactData
38-
this.acceptedAppointment = dd.acceptedAppointment
38+
this.acceptedAppointments = dd.acceptedAppointments
3939

4040
return {
4141
status: Status.Succeeded,

0 commit comments

Comments
 (0)