Skip to content

Commit

Permalink
fix(storage-client): return boolean has in method
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Nov 17, 2022
1 parent ba64195 commit 68123cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/core/storage-client/src/storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ export class AlwatrStorageClient<DocumentType extends DocumentObject> {
timeout: this.config.timeout,
});

let content: ServerResponse<DocumentType>;
let content: ServerResponse<{has: 'true' | 'false'}>;
try {
content = await response.json();
}
catch {
throw new Error('invalid_json');
}

if (content.ok === true) {
if (content.ok === true && content.data.has === 'true') {
return true;
}
else if (content.ok === false && content.errorCode === 'document_not_found') {
if (content.ok === true && content.data.has === 'false') {
return false;
}
else {
Expand Down
11 changes: 1 addition & 10 deletions packages/service/storage-server/src/route/has.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ async function has(connection: AlwatrConnection): Promise<void> {

const storage = storageProvider.get({name: params.storage});

if (!storage.has(params.id)) {
connection.reply({
ok: false,
errorCode: 'document_not_exists',
statusCode: 404,
});
return;
}

connection.reply({
ok: true,
data: {},
data: {has: storage.has(params.id)},
});
}

0 comments on commit 68123cd

Please sign in to comment.