diff --git a/apps/nestjs-backend/src/features/record/open-api/record-open-api.controller.ts b/apps/nestjs-backend/src/features/record/open-api/record-open-api.controller.ts index aeb4f89535..e8b3180b92 100644 --- a/apps/nestjs-backend/src/features/record/open-api/record-open-api.controller.ts +++ b/apps/nestjs-backend/src/features/record/open-api/record-open-api.controller.ts @@ -143,12 +143,12 @@ export class RecordOpenApiController { @Permissions('record|create') @Post(':recordId') - async duplicateRecords( + async duplicateRecord( @Param('tableId') tableId: string, @Param('recordId') recordId: string, @Body(new ZodValidationPipe(recordInsertOrderRoSchema)) order: IRecordInsertOrderRo ) { - return await this.recordOpenApiService.duplicateRecords(tableId, recordId, order); + return await this.recordOpenApiService.duplicateRecord(tableId, recordId, order); } @Permissions('record|delete') diff --git a/apps/nestjs-backend/src/features/record/open-api/record-open-api.service.ts b/apps/nestjs-backend/src/features/record/open-api/record-open-api.service.ts index 70faa1d312..0230b91603 100644 --- a/apps/nestjs-backend/src/features/record/open-api/record-open-api.service.ts +++ b/apps/nestjs-backend/src/features/record/open-api/record-open-api.service.ts @@ -616,7 +616,7 @@ export class RecordOpenApiService { return await this.updateRecord(tableId, recordId, updateRecordRo); } - async duplicateRecords(tableId: string, recordId: string, order: IRecordInsertOrderRo) { + async duplicateRecord(tableId: string, recordId: string, order: IRecordInsertOrderRo) { const query = { fieldKeyType: FieldKeyType.Id }; const result = await this.recordService.getRecord(tableId, recordId, query); const records = { fields: result.fields }; @@ -625,7 +625,10 @@ export class RecordOpenApiService { order, records: [records], }; - const createdRecords = await this.createRecords(tableId, createRecordsRo); + const createdRecords = await this.prismaService.$tx(async () => + this.createRecords(tableId, createRecordsRo) + ); + return { ids: createdRecords.records.map((record) => record.id) }; } } diff --git a/apps/nestjs-backend/test/utils/init-app.ts b/apps/nestjs-backend/test/utils/init-app.ts index 42a0978901..8042650d0f 100644 --- a/apps/nestjs-backend/test/utils/init-app.ts +++ b/apps/nestjs-backend/test/utils/init-app.ts @@ -41,7 +41,7 @@ import { createField as apiCreateField, deleteField as apiDeleteField, convertField as apiConvertField, - duplicateRecords as apiDuplicateRecords, + duplicateRecord as apiDuplicateRecord, getFields as apiGetFields, getField as apiGetField, getViewList as apiGetViewList, @@ -324,7 +324,7 @@ export async function duplicateRecord( expectStatus = 201 ) { try { - const res = await apiDuplicateRecords(tableId, recordId, order); + const res = await apiDuplicateRecord(tableId, recordId, order); expect(res.status).toEqual(expectStatus); return res.data; diff --git a/packages/openapi/src/record/duplicate.ts b/packages/openapi/src/record/duplicate.ts index e2df26fa5f..f81c2cbf03 100644 --- a/packages/openapi/src/record/duplicate.ts +++ b/packages/openapi/src/record/duplicate.ts @@ -41,7 +41,7 @@ export const duplicateRoute = registerRoute({ tags: ['record'], }); -export const duplicateRecords = async ( +export const duplicateRecord = async ( tableId: string, recordId: string, order: IRecordInsertOrderRo diff --git a/packages/sdk/src/components/expand-record/ExpandRecorder.tsx b/packages/sdk/src/components/expand-record/ExpandRecorder.tsx index be3a36d6a6..ac00a243bc 100644 --- a/packages/sdk/src/components/expand-record/ExpandRecorder.tsx +++ b/packages/sdk/src/components/expand-record/ExpandRecorder.tsx @@ -1,5 +1,5 @@ import type { IRecord } from '@teable/core'; -import { deleteRecord, duplicateRecords } from '@teable/openapi'; +import { deleteRecord, duplicateRecord } from '@teable/openapi'; import { useToast } from '@teable/ui-lib'; import { useEffect, type FC, type PropsWithChildren } from 'react'; import { useLocalStorage } from 'react-use'; @@ -74,7 +74,7 @@ export const ExpandRecorder = (props: IExpandRecorderProps) => { } const onDuplicate = async (tableId: string, recordId: string) => { - await duplicateRecords(tableId, recordId, { + await duplicateRecord(tableId, recordId, { viewId: viewId || '', anchorId: recordId, position: 'after',