-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add private route for restore workbook #31
Add private route for restore workbook #31
Conversation
|
||
const model: Optional<WorkbookModel> = await WorkbookModel.query(targetTrx) | ||
.select() | ||
.skipUndefined() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed here and below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnessesary, fixed it, was error when don't have tenantId
[WorkbookModelColumn.TenantId]: tenantId, | ||
[WorkbookModelColumn.WorkbookId]: workbookId, | ||
}) | ||
.andWhereNot(WorkbookModelColumn.DeletedAt, null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check this after the query, like:
if (!model) {
throw new AppError(US_ERRORS.WORKBOOK_NOT_EXISTS, {
code: US_ERRORS.WORKBOOK_NOT_EXISTS,
});
}
if (model.deletedAt !== null) {
throw new AppError(US_ERRORS.WORKBOOK_IS_ALREADY_RESTORED, { // new error with 400 status
code: US_ERRORS.WORKBOOK_IS_ALREADY_RESTORED,
});
}
.first() | ||
.timeout(WorkbookModel.DEFAULT_QUERY_TIMEOUT); | ||
|
||
await Promise.all( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can restore all the entries by one patch query:
UPDATE entries SET
key = regexp_replace(key, '__trash/', ''),
display_key = regexp_replace(display_key, '__trash/', ''),
inner_meta = inner_meta - 'oldKey' - 'oldDisplayKey',
is_deleted = FALSE,
deleted_at = NULL,
updated_at = NOW()
WHERE
tenant_id = '{TENANT_ID}' AND workbook_id = {WORKBOOK_ID} AND deleted_at > '{WORKBOOK_DELETED_AT}';
And getting all the entries above will be unnecessary.
No description provided.