Nest.js项目小结2

2024-04-27 00:04
文章标签 项目 js 小结 nest

本文主要是介绍Nest.js项目小结2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.配置了项目路径别名

        tsconfig.json

{"compilerOptions": {"module": "commonjs","declaration": true,"removeComments": true,"emitDecoratorMetadata": true,"experimentalDecorators": true,"allowSyntheticDefaultImports": true,"target": "ES2021","sourceMap": true,"outDir": "./dist","baseUrl": "./","incremental": true,"skipLibCheck": true,"strictNullChecks": false,"noImplicitAny": false,"strictBindCallApply": false,"forceConsistentCasingInFileNames": false,"noFallthroughCasesInSwitch": false,"paths":{"@/*":["src/*"]}}
}

2.新增了文章功能

        article.controller.ts

import { Controller, Post } from '@nestjs/common'
import { ArticleService } from './article.service'@Controller()
export class ArticleController{constructor(private article: ArticleService) {}@Post("article")findAll(){return this.article.findAll() // 返回的是一个数组}
}

        article.module.ts

import { Module } from '@nestjs/common'
import { ArticleController } from './article.controller';
import { ArticleService } from './article.service';@Module({controllers: [ ArticleController],providers: [ ArticleService]
})export class ArticleModule{}

        article.service.ts

import { Injectable } from '@nestjs/common'
import { PrismaService } from '@/prisma/prisma.service'
import { ConfigService } from '@nestjs/config'@Injectable()
export class ArticleService{constructor(private prisma: PrismaService , private config: ConfigService) {}async findAll(page = 1) {const row = this.config.get('ARTICLE_PAGE_ROW')const articles = await this.prisma.article.findMany({skip: (page - 1) * row,take: +row})const total = await this.prisma.article.count()return {meta: {current_page: page,page_row: row,total,total_page: Math.ceil(total / row) // 向上取整},data: articles}}
}

3.配置了env

DATABASE_URL=# TOKEN密钥
TOKEN_SECRET = # 每页文章数
ARTICLE_PAGE_ROW = 10

4.配置了app.module.ts

import { Module } from '@nestjs/common';
import { AuthModule } from './auth/auth.module';
import { PrismaModule } from './prisma/prisma.module';
import { ArticleModule } from './article/article.module';
import { ConfigModule } from '@nestjs/config';@Module({imports: [ AuthModule , PrismaModule , ArticleModule , ConfigModule.forRoot({ isGlobal: true })],
})
export class AppModule {}

这篇关于Nest.js项目小结2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/939028

相关文章

Spring Boot项目打包和运行的操作方法

《SpringBoot项目打包和运行的操作方法》SpringBoot应用内嵌了Web服务器,所以基于SpringBoot开发的web应用也可以独立运行,无须部署到其他Web服务器中,下面以打包dem... 目录一、打包为JAR包并运行1.打包为可执行的 JAR 包2.运行 JAR 包二、打包为WAR包并运行

CSS引入方式和选择符的讲解和运用小结

《CSS引入方式和选择符的讲解和运用小结》CSS即层叠样式表,是一种用于描述网页文档(如HTML或XML)外观和格式的样式表语言,它主要用于将网页内容的呈现(外观)和结构(内容)分离,从而实现... 目录一、前言二、css 是什么三、CSS 引入方式1、行内样式2、内部样式表3、链入外部样式表四、CSS 选

$在R语言中的作用示例小结

《$在R语言中的作用示例小结》在R语言中,$是一个非常重要的操作符,主要用于访问对象的成员或组件,它的用途非常广泛,不仅限于数据框(dataframe),还可以用于列表(list)、环境(enviro... 目录1. 访问数据框(data frame)中的列2. 访问列表(list)中的元素3. 访问jav

Nginx部署React项目时重定向循环问题的解决方案

《Nginx部署React项目时重定向循环问题的解决方案》Nginx在处理React项目请求时出现重定向循环,通常是由于`try_files`配置错误或`root`路径配置不当导致的,本文给大家详细介... 目录问题原因1. try_files 配置错误2. root 路径错误解决方法1. 检查 try_f

VSCode中配置node.js的实现示例

《VSCode中配置node.js的实现示例》本文主要介绍了VSCode中配置node.js的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 目录一.node.js下载安装教程二.配置npm三.配置环境变量四.VSCode配置五.心得一.no

Redis中HyperLogLog的使用小结

《Redis中HyperLogLog的使用小结》Redis的HyperLogLog是一种概率性数据结构,用于统计唯一元素的数量(基数),本文主要介绍了Redis中HyperLogLog的使用小结,感兴... 目录 一、HyperlogLog 是什么?️ 二、使用方法1. 添加数据2. 查询基数China编程3.

pandas DataFrame keys的使用小结

《pandasDataFramekeys的使用小结》pandas.DataFrame.keys()方法返回DataFrame的列名,类似于字典的键,本文主要介绍了pandasDataFrameke... 目录Pandas2.2 DataFrameIndexing, iterationpandas.DataF

解决Maven项目报错:failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题

《解决Maven项目报错:failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题》这篇文章主要介... 目录Maven项目报错:failed to execute goal org.apache.maven.pl

Java调用Python的四种方法小结

《Java调用Python的四种方法小结》在现代开发中,结合不同编程语言的优势往往能达到事半功倍的效果,本文将详细介绍四种在Java中调用Python的方法,并推荐一种最常用且实用的方法,希望对大家有... 目录一、在Java类中直接执行python语句二、在Java中直接调用Python脚本三、使用Run

Android 12解决push framework.jar无法开机的方法小结

《Android12解决pushframework.jar无法开机的方法小结》:本文主要介绍在Android12中解决pushframework.jar无法开机的方法,包括编译指令、框架层和s... 目录1. android 编译指令1.1 framework层的编译指令1.2 替换framework.ja