Compare commits

..

2 Commits

Author SHA1 Message Date
9d23757f45 add user module and jwt 2025-06-23 21:21:47 +08:00
ddb436cb9a add user module and jwt 2025-06-23 08:41:02 +08:00
6 changed files with 11 additions and 8 deletions

View File

@ -90,6 +90,7 @@ export class PostEntity extends BaseEntity {
@OneToMany(() => CommentEntity, (comment) => comment.post, { cascade: true })
comments: Relation<CommentEntity>[];
@Expose()
@ManyToOne(() => UserEntity, (user) => user.posts, {
nullable: false,
onDelete: 'CASCADE',

View File

@ -1,6 +1,6 @@
import { join } from 'path';
import { Injectable } from '@nestjs/common';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { DataSource, DataSourceOptions } from 'typeorm';
@ -11,7 +11,7 @@ import { TypeormMigrationRun } from '@/modules/database/commands/typeorm.migrati
import { DBOptions } from '@/modules/database/types';
@Injectable()
export class AutoMigrateResolver {
export class AutoMigrateResolver implements OnModuleInit {
constructor(private ref: ModuleRef) {}
async onModuleInit() {

View File

@ -1,4 +1,5 @@
import { Entity, ManyToOne, OneToOne, Relation } from 'typeorm';
import type { Relation } from 'typeorm';
import { Entity, ManyToOne, OneToOne } from 'typeorm';
import { BaseToken } from '@/modules/user/entities/base.token';
import { RefreshTokenEntity } from '@/modules/user/entities/refresh.token.entity';

View File

@ -1,4 +1,5 @@
import { Entity, JoinColumn, OneToOne, Relation } from 'typeorm';
import type { Relation } from 'typeorm';
import { Entity, JoinColumn, OneToOne } from 'typeorm';
import { AccessTokenEntity } from '@/modules/user/entities/access.token.entity';
import { BaseToken } from '@/modules/user/entities/base.token';

View File

@ -1,4 +1,5 @@
import { Exclude, Expose, Type } from 'class-transformer';
import type { Relation } from 'typeorm';
import {
Column,
CreateDateColumn,
@ -6,7 +7,6 @@ import {
Entity,
OneToMany,
PrimaryColumn,
Relation,
UpdateDateColumn,
} from 'typeorm';
@ -50,7 +50,7 @@ export class UserEntity {
*
*/
@Expose()
@Column({ comment: '用户手机号', length: 64, nullable: false, unique: true })
@Column({ comment: '用户手机号', length: 64, nullable: true, unique: true })
phone?: string;
/**

View File

@ -1,6 +1,6 @@
import { BadGatewayException, ExecutionContext, Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { plainToClass } from 'class-transformer';
import { plainToInstance } from 'class-transformer';
import { validateOrReject } from 'class-validator';
@ -14,7 +14,7 @@ export class LocalAuthGuard extends AuthGuard('local') {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest();
try {
await validateOrReject(plainToClass(CredentialDto, request.body), {
await validateOrReject(plainToInstance(CredentialDto, request.body), {
validationError: { target: false },
});
} catch (error) {