Skip to content
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

Merged
merged 13 commits into from
Dec 7, 2023

Conversation

Sergey-weber
Copy link
Collaborator

No description provided.

@Sergey-weber Sergey-weber changed the title Charts 8714 add private route for restore workbook Add private route for restore workbook Nov 30, 2023

const model: Optional<WorkbookModel> = await WorkbookModel.query(targetTrx)
.select()
.skipUndefined()
Copy link
Collaborator

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?

Copy link
Collaborator Author

@Sergey-weber Sergey-weber Dec 6, 2023

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)
Copy link
Collaborator

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(
Copy link
Collaborator

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.

@Sergey-weber Sergey-weber merged commit ce1cb0e into main Dec 7, 2023
3 checks passed
@Sergey-weber Sergey-weber deleted the CHARTS-8714-add-private-route-for-restore-workbook branch December 7, 2023 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants