Skip to content

Commit

Permalink
Enhance deleteById to be consistent with findById
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Nov 9, 2023
1 parent b76ba39 commit 78244ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 12 additions & 3 deletions data_mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,24 @@ export class DataMapper<Def extends Definition> {
});
}

async deleteById(args: DataMapperIdQueryArgs): Promise<DeleteResponse> {
const datastore = args.datastore ?? this.#defaultDatastore;
async deleteById(
args: DataMapperIdQueryArgs | string,
): Promise<DeleteResponse> {
let datastore = this.#defaultDatastore;
let id = undefined;
if (typeof args === "string") {
id = args;
} else {
id = args.id;
datastore = args.datastore ?? this.#defaultDatastore;
}
if (!datastore) {
throw new ConfigurationError(this.#datastoreMissingError);
}
return await func.deleteById({
client: this.#client,
datastore,
id: args.id,
id,
logger: this.#logger,
});
}
Expand Down
10 changes: 10 additions & 0 deletions data_mapper_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ mf.mock("POST@/api/apps.datastore.get", () => {
);
});

mf.mock("POST@/api/apps.datastore.delete", () => {
return new Response(
JSON.stringify({ "ok": true }),
{ status: 200 },
);
});

export const Surveys = DefineDatastore(
{
name: "surveys",
Expand Down Expand Up @@ -146,6 +153,9 @@ Deno.test("Run a query", async () => {
attributes: { "#title": "title" },
values: { ":title": "Off-site event ideas" },
});

await dataMapper.deleteById("123");
await dataMapper.deleteById({ id: "123" });
});

Deno.test("Run a query with simple expressions", async () => {
Expand Down

0 comments on commit 78244ef

Please sign in to comment.