fixes: new components db transaction fails for newly created pages

This commit is contained in:
arpitnath 2023-09-05 02:37:57 +05:30
parent 743fc2aadf
commit c5622a139b
5 changed files with 17 additions and 9 deletions

View file

@ -851,7 +851,7 @@ const EditorComponent = (props) => {
};
const realtimeSave = debounce(appDefinitionChanged, 500);
const autoSave = debounce(saveEditingVersion, 3000);
const autoSave = debounce(saveEditingVersion, 200);
function handlePaths(prevPatch, path = [], appJSON) {
const paths = [...path];
@ -1121,6 +1121,7 @@ const EditorComponent = (props) => {
const newPageId = uuid();
copyOfAppDefinition.pages[newPageId] = {
id: newPageId,
name,
handle: newHandle,
components: {},

View file

@ -164,7 +164,7 @@ export class AppsControllerV2 {
throw new ForbiddenException('You do not have permissions to perform this action');
}
await this.componentsService.create(versionEditDto.diff, versionEditDto.pageId);
await this.componentsService.create(versionEditDto.diff, versionEditDto.pageId, versionId);
}
@UseGuards(JwtAuthGuard)

View file

@ -1,6 +1,9 @@
import { IsNumber, IsString } from 'class-validator';
import { IsNumber, IsString, IsUUID } from 'class-validator';
export class CreatePageDto {
@IsUUID()
id: string;
@IsString()
name: string;

View file

@ -21,9 +21,11 @@ export class ComponentsService {
return this.componentsRepository.findOne(id);
}
async create(componentDiff: object, pageId: string) {
async create(componentDiff: object, pageId: string, appVersionId: string) {
return dbTransactionWrap(async (manager: EntityManager) => {
const page = await manager.findOne(Page, pageId);
const page = await manager.findOne(Page, {
where: { appVersionId, id: pageId },
});
const newComponents = this.transformComponentData(componentDiff);
const componentLayouts = [];

View file

@ -39,10 +39,12 @@ export class PageService {
}
async createPage(page: CreatePageDto, appVersionId: string): Promise<Page> {
const newPage = {
...page,
appVersionId: appVersionId,
};
const newPage = new Page();
newPage.id = page.id;
newPage.name = page.name;
newPage.handle = page.handle;
newPage.index = page.index;
newPage.appVersionId = appVersionId;
return this.pageRepository.save(newPage);
}