Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion openapi.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hash": "ce722f966bbb3c4eabd198291cd5cdc8eebf36391ba8eb0458d107822cfc8037",
"hash": "3c5196d98b6096d6dcb28beda5cf923b703ff18e399556d63feff0bbccf7038b",
"openapi": "3.0.0",
"paths": {
"/hello": {
Expand Down Expand Up @@ -2353,6 +2353,14 @@
"type": "string"
}
},
{
"name": "key",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "_limit",
"required": false,
Expand Down Expand Up @@ -2518,6 +2526,14 @@
"type": "string"
}
},
{
"name": "key",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "_limit",
"required": false,
Expand Down Expand Up @@ -6807,6 +6823,9 @@
"CreateSessionDto": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"expireAt": {
"format": "date-time",
"type": "string",
Expand Down Expand Up @@ -7002,6 +7021,9 @@
"remark": {
"type": "string",
"description": "备注"
},
"key": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -8428,6 +8450,9 @@
"type": "string",
"description": "备注"
},
"key": {
"type": "string"
},
"_limit": {
"type": "number",
"description": "分页大小"
Expand Down
7 changes: 6 additions & 1 deletion src/session/dto/create-session.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { OmitType } from '@nestjs/swagger';
import { IsOptional, IsString } from 'class-validator';

import { SessionDoc } from '../entities/session.entity';

export class CreateSessionDto extends OmitType(SessionDoc, ['key'] as const) {}
export class CreateSessionDto extends OmitType(SessionDoc, ['key'] as const) {
@IsOptional()
@IsString()
key?: string;
}
5 changes: 3 additions & 2 deletions src/session/session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export class SessionService {
constructor(@InjectModel(Session.name) private readonly sessionModel: Model<SessionDocument>) {}

create(createDto: CreateSessionDto): Promise<SessionDocument> {
const key = nanoid();
const session = new this.sessionModel({ ...createDto, key });
const { key: customKey, ...rest } = createDto;
const key = customKey ?? nanoid();
const session = new this.sessionModel({ ...rest, key });
return session.save();
}

Expand Down
Loading