Skip to content

Commit

Permalink
Update BrowserFormRepository for interface changes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnaab committed Nov 25, 2024
1 parent 8377230 commit 45a202d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/forms/src/context/browser/form-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,22 @@ export class BrowserFormRepository implements FormRepository {
};
}

async deleteForm(formId: string): Promise<VoidResult> {
async deleteForm(
formId: string
): Promise<VoidResult<{ message: string; code: 'not-found' | 'unknown' }>> {
this.storage.removeItem(formKey(formId));
return { success: true };
}

async getForm(id?: string): Promise<Blueprint | null> {
async getForm(id?: string): Promise<Result<Blueprint | null>> {
if (!this.storage || !id) {
return null;
return success(null);
}
const formString = this.storage.getItem(`forms/${id}`);
if (!formString) {
return null;
return success(null);
}
return Promise.resolve(JSON.parse(formString));
return Promise.resolve(success(JSON.parse(formString)));
}

async getFormList(): Promise<
Expand All @@ -105,14 +107,17 @@ export class BrowserFormRepository implements FormRepository {
}
return Promise.all(
forms.map(async key => {
const form = await this.getForm(key);
if (form === null) {
const formResult = await this.getForm(key);
if (!formResult.success) {
throw new Error('Error getting form');
}
if (formResult.data === null) {
throw new Error('key mismatch');
}
return {
id: key,
title: form.summary.title,
description: form.summary.description,
title: formResult.data.summary.title,
description: formResult.data.summary.description,
};
})
);
Expand Down

0 comments on commit 45a202d

Please sign in to comment.