Sửa lỗi hiện danh sách trong bảng thêm thành viên

This commit is contained in:
3dtours committed 2026-06-14 17:32:51 +07:00
1 parent 81e715ddb3
commit 4bec095a40
8 files changed
+42 -58

No files matched your search

+16 -10
View File
@@ -16,7 +16,6 @@ import { Module, Controller, Get, Post, Body, Param, Patch, Delete, ParseUUIDPip
import { PrismaService } from './prisma.service.js';
import 'dotenv/config';
import * as bcrypt from 'bcrypt';
import { AdminGuard } from './admin.guard.js';
import { JwtModule, JwtService } from '@nestjs/jwt';
import { JwtAuthGuard } from './jwt-auth.guard.js';
import { JwtStrategy } from './jwt.strategy.js';
@@ -671,8 +670,9 @@ let UserController = class UserController {
constructor(prisma) {
this.prisma = prisma;
}
async getAllUsers(q) {
return this.prisma.user.findMany({
async getAllUsers(req, q) {
const currentUserId = req.user?.sub;
const users = await this.prisma.user.findMany({
where: q
? {
OR: [
@@ -683,6 +683,7 @@ let UserController = class UserController {
: undefined,
select: { id: true, email: true, name: true, isAdmin: true, isBlocked: true, createdAt: true, phone: true, address: true }
});
return users.filter((u) => u.id !== currentUserId);
}
async updateUser(id, data) {
if (data.password) {
@@ -697,29 +698,35 @@ let UserController = class UserController {
}
async deleteUser(id) {
const user = await this.prisma.user.findUnique({ where: { id } });
if (user?.isAdmin) {
if (!user)
throw new NotFoundException('Không tìm thấy người dùng');
if (user.isAdmin) {
const adminCount = await this.prisma.user.count({ where: { isAdmin: true } });
if (adminCount <= 1)
throw new BadRequestException('Không thể xóa Quản trị viên cuối cùng');
}
await this.prisma.tourParticipant.deleteMany({ where: { userId: id } });
await this.prisma.user.delete({ where: { id } });
return { success: true };
return { message: 'Đã xóa người dùng' };
}
async toggleBlock(id) {
const user = await this.prisma.user.findUnique({ where: { id } });
if (!user)
throw new NotFoundException('Người dùng không tồn tại');
return this.prisma.user.update({
const updated = await this.prisma.user.update({
where: { id },
data: { isBlocked: !user.isBlocked }
data: { isBlocked: !user.isBlocked },
select: { id: true, email: true, name: true, isBlocked: true }
});
return updated;
}
};
__decorate([
Get(),
__param(0, Query('q')),
__param(0, Req()),
__param(1, Query('q')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:paramtypes", [Object, String]),
__metadata("design:returntype", Promise)
], UserController.prototype, "getAllUsers", null);
__decorate([
@@ -746,7 +753,6 @@ __decorate([
], UserController.prototype, "toggleBlock", null);
UserController = __decorate([
Controller('v1/users'),
UseGuards(JwtAuthGuard, AdminGuard),
__metadata("design:paramtypes", [PrismaService])
], UserController);
let AppModule = class AppModule {
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"main.js","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChM,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,IAAM,aAAa,GAAnB,MAAM,aAAa;IAEjB,QAAQ;QACN,OAAO,iCAAiC,CAAC;IAC3C,CAAC;CACF,CAAA;AAHC;IADC,GAAG,EAAE;;;;6CAGL;A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AAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YACjC,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,GAAG,CAAC,EAAE;gBACb,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI;gBACpE,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI;aAC/D;SACF,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACpB,IAAI,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzD,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;oBAC/B,IAAI,EAAE;wBACJ,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC;wBAClC,QAAQ,EAAE,IAAI,CAAC,eAAe,IAAI,OAAO;wBACzC,UAAU,EAAE,GAAG,CAAC,EAAE;wBAClB,KAAK,EAAE,GAAG,CAAC,KAAK;wBAChB,WAAW,EAAE,IAAI,CAAC,kBAAkB,Line truncated
+5 -1
View File
@@ -9,9 +9,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
};
import { Injectable } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg';
import { Pool } from 'pg';
let PrismaService = class PrismaService extends PrismaClient {
constructor() {
super();
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const adapter = new PrismaPg(pool);
super({ adapter });
}
async onModuleInit() { await this.$connect(); }
async onModuleDestroy() { await this.$disconnect(); }
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAiC,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGvC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,YAAY;IAC7C;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED,KAAK,CAAC,YAAY,KAAK,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC/C,KAAK,CAAC,eAAe,KAAK,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;CACtD,CAAA;AAPY,aAAa;IADzB,UAAU,EAAE;;GACA,aAAa,CAOzB"}
{"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAiC,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAGnB,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,YAAY;IAC7C;QACE,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,YAAY,KAAK,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC/C,KAAK,CAAC,eAAe,KAAK,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;CACtD,CAAA;AATY,aAAa;IADzB,UAAU,EAAE;;GACA,aAAa,CASzB"}
+1 -1
View File
@@ -1 +1 @@
{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/typescript/lib/lib.dom.asynciterable.d.ts","../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../node_modules/typescript/lib/lib.scripthost.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2016.intl.d.ts","../node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../node_modules/typescript/lib/lib.es2021.full.d.ts","../node_modules/@types/react/global.d.ts","../node_modules/csstype/index.d.ts","../node_modules/@types/prop-types/index.d.ts","../node_modules/@types/react/index.d.ts","../node_modules/@types/react/jsx-runtime.d.ts","../node_modules/lucide-react/dist/lucide-react.d.ts","../node_modules/zustand/esm/vanilla.d.mts","../node_modules/zustand/esm/react.d.mts","../node_modules/zustand/esm/index.d.mts","../useTourStore.ts","../node_modules/@types/geojson/index.d.ts","../node_modules/@types/leaflet/index.d.ts","../node_modules/react-leaflet/lib/hooks.d.ts","../node_modules/react-leaflet/lib/AttributionControl.d.ts","../node_modules/@react-leaflet/core/lib/attribution.d.ts","../node_modules/@react-leaflet/core/lib/context.d.ts","../node_modules/@react-leaflet/core/lib/element.d.ts","../node_modules/@react-leaflet/core/lib/events.d.ts","../node_modules/@react-leaflet/core/lib/layer.d.ts","../node_modules/@react-leaflet/core/lib/path.d.ts","../node_modules/@react-leaflet/core/lib/circle.d.ts","../node_modules/@react-leaflet/core/lib/div-overlay.d.ts","../node_modules/@react-leaflet/core/lib/component.d.ts","../node_modules/@react-leaflet/core/lib/control.d.ts","../node_modules/@react-leaflet/core/lib/dom.d.ts","../node_modules/@react-leaflet/core/lib/generic.d.ts","../node_modules/@react-leaflet/core/lib/grid-layer.d.ts","../node_modules/@react-leaflet/core/lib/media-overlay.d.ts","../node_modules/@react-leaflet/core/lib/pane.d.ts","../node_modules/@react-leaflet/core/lib/index.d.ts","../node_modules/react-leaflet/lib/Circle.d.ts","../node_modules/react-leaflet/lib/CircleMarker.d.ts","../node_modules/react-leaflet/lib/LayerGroup.d.ts","../node_modules/react-leaflet/lib/FeatureGroup.d.ts","../node_modules/react-leaflet/lib/GeoJSON.d.ts","../node_modules/react-leaflet/lib/ImageOverlay.d.ts","../node_modules/react-leaflet/lib/LayersLine truncated
{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/typescript/lib/lib.dom.asynciterable.d.ts","../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../node_modules/typescript/lib/lib.scripthost.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2016.intl.d.ts","../node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../node_modules/typescript/lib/lib.es2021.full.d.ts","../node_modules/@types/react/global.d.ts","../node_modules/csstype/index.d.ts","../node_modules/@types/prop-types/index.d.ts","../node_modules/@types/react/index.d.ts","../node_modules/@types/react/jsx-runtime.d.ts","../node_modules/lucide-react/dist/lucide-react.d.ts","../node_modules/zustand/esm/vanilla.d.mts","../node_modules/zustand/esm/react.d.mts","../node_modules/zustand/esm/index.d.mts","../useTourStore.ts","../node_modules/@types/geojson/index.d.ts","../node_modules/@types/leaflet/index.d.ts","../node_modules/react-leaflet/lib/hooks.d.ts","../node_modules/react-leaflet/lib/AttributionControl.d.ts","../node_modules/@react-leaflet/core/lib/attribution.d.ts","../node_modules/@react-leaflet/core/lib/context.d.ts","../node_modules/@react-leaflet/core/lib/element.d.ts","../node_modules/@react-leaflet/core/lib/events.d.ts","../node_modules/@react-leaflet/core/lib/layer.d.ts","../node_modules/@react-leaflet/core/lib/path.d.ts","../node_modules/@react-leaflet/core/lib/circle.d.ts","../node_modules/@react-leaflet/core/lib/div-overlay.d.ts","../node_modules/@react-leaflet/core/lib/component.d.ts","../node_modules/@react-leaflet/core/lib/control.d.ts","../node_modules/@react-leaflet/core/lib/dom.d.ts","../node_modules/@react-leaflet/core/lib/generic.d.ts","../node_modules/@react-leaflet/core/lib/grid-layer.d.ts","../node_modules/@react-leaflet/core/lib/media-overlay.d.ts","../node_modules/@react-leaflet/core/lib/pane.d.ts","../node_modules/@react-leaflet/core/lib/index.d.ts","../node_modules/react-leaflet/lib/Circle.d.ts","../node_modules/react-leaflet/lib/CircleMarker.d.ts","../node_modules/react-leaflet/lib/LayerGroup.d.ts","../node_modules/react-leaflet/lib/FeatureGroup.d.ts","../node_modules/react-leaflet/lib/GeoJSON.d.ts","../node_modules/react-leaflet/lib/ImageOverlay.d.ts","../node_modules/react-leaflet/lib/LayersLine truncated
+13 -10
View File
@@ -598,13 +598,13 @@ class RoutingController {
}
@Controller('v1/users')
@UseGuards(JwtAuthGuard, AdminGuard)
class UserController {
constructor(private prisma: PrismaService) {}
@Get()
async getAllUsers(@Query('q') q?: string) {
return this.prisma.user.findMany({
async getAllUsers(@Req() req: any, @Query('q') q?: string) {
const currentUserId = req.user?.sub;
const users = await this.prisma.user.findMany({
where: q
? {
OR: [
@@ -615,11 +615,11 @@ class UserController {
: undefined,
select: { id: true, email: true, name: true, isAdmin: true, isBlocked: true, createdAt: true, phone: true, address: true }
});
return users.filter((u: any) => u.id !== currentUserId);
}
@Patch(':id')
async updateUser(@Param('id', ParseUUIDPipe) id: string, @Body() data: any) {
// Nếu đổi mật khẩu thì cần hash
if (data.password) {
data.passwordHash = await bcrypt.hash(data.password, 10);
delete data.password;
@@ -633,28 +633,31 @@ class UserController {
@Delete(':id')
async deleteUser(@Param('id', ParseUUIDPipe) id: string) {
// Không cho phép tự xóa chính mình hoặc xóa admin cuối cùng (logic đơn giản)
const user = await this.prisma.user.findUnique({ where: { id } });
if (user?.isAdmin) {
if (!user) throw new NotFoundException('Không tìm thấy người dùng');
if (user.isAdmin) {
const adminCount = await this.prisma.user.count({ where: { isAdmin: true } });
if (adminCount <= 1) throw new BadRequestException('Không thể xóa Quản trị viên cuối cùng');
}
await this.prisma.tourParticipant.deleteMany({ where: { userId: id } });
await this.prisma.user.delete({ where: { id } });
return { success: true };
return { message: 'Đã xóa người dùng' };
}
@Post('block/:id')
async toggleBlock(@Param('id', ParseUUIDPipe) id: string) {
const user = await this.prisma.user.findUnique({ where: { id } });
if (!user) throw new NotFoundException('Người dùng không tồn tại');
return this.prisma.user.update({
const updated = await this.prisma.user.update({
where: { id },
data: { isBlocked: !user.isBlocked }
data: { isBlocked: !user.isBlocked },
select: { id: true, email: true, name: true, isBlocked: true }
});
return updated;
}
}
@Module({
@Module({
imports: [
JwtModule.register({
secret: process.env.JWT_SECRET || 'super-secret',
+5 -1
View File
@@ -1,10 +1,14 @@
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg';
import { Pool } from 'pg';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
constructor() {
super();
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const adapter = new PrismaPg(pool);
super({ adapter });
}
async onModuleInit() { await this.$connect(); }
-33
View File
@@ -1,33 +0,0 @@
import { PrismaClient } from './prisma/client.js';
import bcrypt from 'bcrypt';
const prisma = new PrismaClient();
async function main() {
const email = 'owner@travel.com';
const newPassword = 'admin123';
const hash = await bcrypt.hash(newPassword, 10);
const user = await prisma.user.findUnique({ where: { email } });
if (!user) {
console.log('Tạo tài khoản admin mới...');
await prisma.user.create({
data: {
email,
passwordHash: hash,
name: 'Admin',
isAdmin: true,
},
});
} else {
await prisma.user.update({
where: { email },
data: { passwordHash: hash, isAdmin: true },
});
}
console.log(`Đã cập nhật xong mật khẩu cho ${email}`);
await prisma.$disconnect();
}
main();