| 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose' |
| 2 | import { DEFAULT_SCHEMA_OPTIONS } from '../mongodb.constants' |
| 3 | import { WithTimestampSchema } from './timestamp.schema' |
| 4 | |
| 5 | @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'apiKey' }) |
| 6 | export class ApiKey extends WithTimestampSchema { |
| 7 | id: string |
| 8 | |
| 9 | @Prop({ required: true, index: true }) |
| 10 | userId: string |
| 11 | |
| 12 | @Prop({ required: true }) |
| 13 | name: string |
| 14 | |
| 15 | @Prop({ required: true, unique: true, index: true }) |
| 16 | keyHash: string |
| 17 | |
| 18 | @Prop() |
| 19 | lastUsedAt: Date |
| 20 | } |
| 21 | |
| 22 | export const ApiKeySchema = SchemaFactory.createForClass(ApiKey) |
| 23 |