Sửa lỗi backend để chạy phần đăng ký
This commit is contained in:
Vendored
+76
-18
@@ -1,4 +1,3 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
@@ -11,29 +10,82 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core_1 = require("@nestjs/core");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("./prisma.service");
|
||||
require("dotenv/config");
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { Module, Controller, Get, Post, Body, Param, ParseIntPipe, NotFoundException, BadRequestException } from '@nestjs/common';
|
||||
import { PrismaService } from './prisma.service.js';
|
||||
import 'dotenv/config';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
let AppController = class AppController {
|
||||
getHello() {
|
||||
return 'Travel Planning API is running!';
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
Get(),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", String)
|
||||
], AppController.prototype, "getHello", null);
|
||||
AppController = __decorate([
|
||||
(0, common_1.Controller)()
|
||||
Controller()
|
||||
], AppController);
|
||||
let AuthController = class AuthController {
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async getStatus() {
|
||||
const userCount = await this.prisma.user.count();
|
||||
return { isInitialSetup: userCount === 0 };
|
||||
}
|
||||
async signup(body) {
|
||||
const { email, password, name } = body;
|
||||
const existingUser = await this.prisma.user.findUnique({ where: { email } });
|
||||
if (existingUser)
|
||||
throw new BadRequestException('Email đã được sử dụng');
|
||||
const userCount = await this.prisma.user.count();
|
||||
const shouldBeAdmin = userCount === 0;
|
||||
const passwordHash = await bcrypt.hash(password, 10);
|
||||
return this.prisma.user.create({
|
||||
data: { email, passwordHash, name, isAdmin: shouldBeAdmin },
|
||||
select: { id: true, email: true, name: true, isAdmin: true }
|
||||
});
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
Get('status'),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "getStatus", null);
|
||||
__decorate([
|
||||
Post('signup'),
|
||||
__param(0, Body()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "signup", null);
|
||||
AuthController = __decorate([
|
||||
Controller('v1/auth'),
|
||||
__metadata("design:paramtypes", [PrismaService])
|
||||
], AuthController);
|
||||
let TourController = class TourController {
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async getPublicTours() {
|
||||
return this.prisma.tour.findMany({
|
||||
take: 20,
|
||||
include: {
|
||||
photos: { take: 1 },
|
||||
legs: {
|
||||
take: 1,
|
||||
include: {
|
||||
places: { take: 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
async getTourDetails(id) {
|
||||
const tour = await this.prisma.tour.findUnique({
|
||||
where: { id },
|
||||
@@ -50,32 +102,38 @@ let TourController = class TourController {
|
||||
},
|
||||
});
|
||||
if (!tour)
|
||||
throw new common_1.NotFoundException(`Không tìm thấy Tour với ID ${id}`);
|
||||
throw new NotFoundException(`Không tìm thấy Tour với ID ${id}`);
|
||||
return tour;
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)(':id'),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
||||
Get('explore'),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], TourController.prototype, "getPublicTours", null);
|
||||
__decorate([
|
||||
Get(':id'),
|
||||
__param(0, Param('id', ParseIntPipe)),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Number]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], TourController.prototype, "getTourDetails", null);
|
||||
TourController = __decorate([
|
||||
(0, common_1.Controller)('api/v1/tours'),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
Controller('v1/tours'),
|
||||
__metadata("design:paramtypes", [PrismaService])
|
||||
], TourController);
|
||||
let AppModule = class AppModule {
|
||||
};
|
||||
AppModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
controllers: [AppController, TourController],
|
||||
providers: [prisma_service_1.PrismaService],
|
||||
exports: [prisma_service_1.PrismaService]
|
||||
Module({
|
||||
controllers: [AppController, AuthController, TourController],
|
||||
providers: [PrismaService],
|
||||
exports: [PrismaService]
|
||||
})
|
||||
], AppModule);
|
||||
async function bootstrap() {
|
||||
const app = await core_1.NestFactory.create(AppModule);
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.enableCors();
|
||||
app.setGlobalPrefix('api');
|
||||
const port = process.env.PORT || 3001;
|
||||
|
||||
Reference in New Issue
Block a user