Skip to content

Commit

Permalink
Add implementation sans tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andresuribe87 committed Oct 7, 2024
1 parent d667090 commit 0d52596
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/dwn-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@ export enum DwnErrorCode {
UrlProtocolNotNormalized = 'UrlProtocolNotNormalized',
UrlProtocolNotNormalizable = 'UrlProtocolNotNormalizable',
UrlSchemaNotNormalized = 'UrlSchemaNotNormalized',
RecordsReadInitialWriteNotFound = 'RecordsReadInitialWriteNotFound',
};
16 changes: 16 additions & 0 deletions src/handlers/records-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ export class RecordsReadHandler implements MethodHandler {
if (matchedMessage.descriptor.method === DwnMethodName.Delete) {
const recordsDeleteMessage = matchedMessage as RecordsDeleteMessage;
const initialWrite = await RecordsWrite.fetchInitialRecordsWriteMessage(this.messageStore, tenant, recordsDeleteMessage.descriptor.recordId);

if (initialWrite === undefined) {
return messageReplyFromError(new DwnError(
DwnErrorCode.RecordsReadInitialWriteNotFound,
'Initial write for deleted record not found'
), 400);
}

// Perform authorization before returning the delete and initial write messages
const parsedInitialWrite = await RecordsWrite.parse(initialWrite);
try {
await RecordsReadHandler.authorizeRecordsRead(tenant, recordsRead, parsedInitialWrite, this.messageStore);
} catch (error) {
return messageReplyFromError(error, 401);
}

return {
status : { code: 404, detail: 'Not Found' },
delete : recordsDeleteMessage,
Expand Down

0 comments on commit 0d52596

Please sign in to comment.