Skip to content

Commit

Permalink
Merge pull request #1128 from undb-xyz/release/v0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin authored Jun 8, 2023
2 parents 3e6abde + cd9828c commit 3135720
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish-new-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ jobs:
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
- name: Create Release
uses: thomaseizinger/create-release@1.0.0
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
- name: Release
uses: softprops/action-gh-release@v1
with:
target_commitish: ${{ github.event.pull_request.merge_commit_sha }}
token: ${{ secrets.PAT }}
tag_name: ${{ env.RELEASE_VERSION }}
name: ${{ env.RELEASE_VERSION }}
generate_release_notes: true
draft: false
prerelease: false
target_commitish: ${{ github.event.pull_request.merge_commit_sha }}

- name: Merge main into develop branch
uses: thomaseizinger/create-pull-request@1.3.0
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## v0.5.2

## v0.5.1


Expand Down
23 changes: 21 additions & 2 deletions apps/backend/src/openapi/openapi.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Body, Controller, Delete, Get, Param, Query, UseGuards, Version } from '@nestjs/common'
import { Body, Controller, Delete, Get, Param, Post, Query, UseGuards, Version } from '@nestjs/common'
import { CommandBus, QueryBus } from '@nestjs/cqrs'
import { BulkDeleteRecordsCommand, DeleteRecordCommand, GetRecordQuery, GetRecordsQuery } from '@undb/cqrs'
import {
BulkDeleteRecordsCommand,
BulkDuplicateRecordsCommand,
DeleteRecordCommand,
DuplicateRecordCommand,
GetRecordQuery,
GetRecordsQuery,
} from '@undb/cqrs'
import { JwtAuthGuard } from '../auth/jwt-auth.guard.js'
import { OpenAPIService } from './openapi.service.js'

Expand Down Expand Up @@ -43,4 +50,16 @@ export class OpenAPIController {
public async deleteRecordsByIds(@Param('tableId') tableId: string, @Body('ids') ids: [string, ...string[]]) {
await this.commandBus.execute(new BulkDeleteRecordsCommand({ tableId, ids }))
}

@Version('1')
@Post('tables/:tableId/records/:id')
public async duplicateRecordById(@Param('tableId') tableId: string, @Param('id') id: string) {
await this.commandBus.execute(new DuplicateRecordCommand({ tableId, id }))
}

@Version('1')
@Post('tables/:tableId/records')
public async duplicateRecordsByIds(@Param('tableId') tableId: string, @Body('ids') ids: [string, ...string[]]) {
await this.commandBus.execute(new BulkDuplicateRecordsCommand({ tableId, ids }))
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "undb",
"version": "0.5.1",
"version": "0.5.2",
"devDependencies": {
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.6.5",
Expand Down
4 changes: 4 additions & 0 deletions packages/openapi/src/create-openapi-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { OpenAPIObject } from 'openapi3-ts/oas30'
import { COMPONENT_OPTION, COMPONENT_RECORD, COMPONENT_RECORD_ID, COMPONENT_USER, COMPONENT_VIEW_ID } from './constants'
import { deleteRecordById } from './routes/delete-record-by-id'
import { deleteRecordsByIds } from './routes/delete-records-by-ids'
import { duplicateRecordById } from './routes/duplicate-record-by-id'
import { duplicateRecordsByIds } from './routes/duplicate-records-by-ids'
import { getRecordById } from './routes/get-record-by-id'
import { getRecords } from './routes/get-records'
import { create401ResponseSchema } from './schema/401.respoonse'
Expand All @@ -34,6 +36,8 @@ export const createTableSchema = (table: Table, record?: IQueryRecordSchema): Op
const routes = [
getRecords(table, recordSchema),
getRecordById(table, recordSchema),
duplicateRecordById(table),
duplicateRecordsByIds(table),
deleteRecordById(table),
deleteRecordsByIds(table),
]
Expand Down
24 changes: 24 additions & 0 deletions packages/openapi/src/routes/duplicate-record-by-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { RouteConfig } from '@asteasolutions/zod-to-openapi'
import { recordIdSchema, type Table } from '@undb/core'
import { z } from 'zod'
import { COMPONENT_RECORD_ID, TAG_RECORD } from '../constants.js'

export const duplicateRecordById = (table: Table): RouteConfig => {
return {
method: 'post',
path: `/tables/${table.id.value}/records/{id}`,
description: `Duplicate ${table.name.value} record by id`,
summary: `Duplicate ${table.name.value} record by id`,
tags: [TAG_RECORD],
request: {
params: z.object({
id: recordIdSchema.openapi(COMPONENT_RECORD_ID),
}),
},
responses: {
200: {
description: `duplciate record success`,
},
},
}
}
32 changes: 32 additions & 0 deletions packages/openapi/src/routes/duplicate-records-by-ids.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { RouteConfig } from '@asteasolutions/zod-to-openapi'
import { recordIdSchema, type Table } from '@undb/core'
import { z } from 'zod'
import { COMPONENT_RECORD_ID, TAG_RECORD } from '../constants.js'

export const duplicateRecordsByIds = (table: Table): RouteConfig => {
return {
method: 'post',
path: `/tables/${table.id.value}/records`,
description: `Duplicate ${table.name.value} records by ids`,
summary: `Duplicate ${table.name.value} records by ids`,
tags: [TAG_RECORD],
request: {
body: {
description: 'duplicate records ids',
required: true,
content: {
'application/json': {
schema: z.object({
ids: recordIdSchema.openapi(COMPONENT_RECORD_ID).array().nonempty(),
}),
},
},
},
},
responses: {
200: {
description: 'duplicate records success',
},
},
}
}

0 comments on commit 3135720

Please sign in to comment.