有人有如何使用 GraphQl 在 NestJs 中上传文件的示例吗?
我可以通过控制器使用给定的示例上传
https://github.com/nestjs/nest/issues/262#issuecomment-366098589,
但我找不到任何全面的文档如何在 NestJS 中使用 GrahpQL 上传
是否可以使用不同的参数多次运行一个 NestJS WebSocketGateway?也许可以为此使用微服务?
我目前正在为我创建的一些开发人员静态文档提供静态文件,我目前正在使用
app.useStaticAssets(docsLocation, {
prefix: "/docs/"
})
Run Code Online (Sandbox Code Playgroud)
我的问题是,我有另一个想要提供服务的目录,它也有静态内容,是否可以从不同的位置提供服务并为每个位置使用不同的前缀?
任何想法,这都没有在文档中涵盖。
谢谢
我正在测试以下服务:
\n\nimport { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';\nimport { InjectRepository } from '@nestjs/typeorm';\nimport { extend } from 'lodash';\nimport { Repository } from 'typeorm';\n\nimport { DriverDTO } from './driver.dto';\nimport { DriverEntity } from './driver.entity';\n\n@Injectable()\nexport class DriverService {\n private logger = new Logger('DriverService');\n constructor(\n @InjectRepository(DriverEntity)\n private driverRepository: Repository<DriverEntity>,\n ) { }\n\n async create(clientId: string, data: DriverDTO): Promise<Partial<DriverEntity>> {\n let driver = await this.driverRepository.findOne({ where: { clientId, driverId: data.driverId } });\n this.logger.log(driver);\n if (driver) {\n throw new HttpException('Driver already exists', …Run Code Online (Sandbox Code Playgroud) 在 auth 模块中,我尝试从 usermodule 访问 userservice 类,收到类似无法找到模块 src/user/user.service 的错误,请查找示例代码 ---
提前致谢。
认证模块
@Module({
imports : [UserModule],
controllers: [AuthController],
providers: [JwtStrategy, AuthService],
exports : [JwtStrategy, AuthService]
})
export class AuthModule {}
Run Code Online (Sandbox Code Playgroud)
用户模块
@Module({
imports : [ MongooseModule.forFeature([{ name : 'User', schema : UserSchema }])],
controllers: [UserController],
providers: [UserService],
exports : [UserService, MongooseModule.forFeature([{ name : 'User', schema : UserSchema }])]
})
export class UserModule {}
Run Code Online (Sandbox Code Playgroud)
应用程序模块
imports: [
AuthModule,
UserModule,
MongooseModule.forRoot('--',
)],
controllers: [AppController],
providers: [AppService]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud) 目前我已经实现了 jwt 防护,它工作得很好,使用 Passport,jwt 正在验证颁发的令牌,我可以通过 @Request 通过 req.user 查看用户,在实现基于角色的身份验证作为已经工作的附加组件后出现问题JWT 的守卫。
我遵循了 Nestjs.com 提供的指导,但没有帮助。 https://docs.nestjs.com/guards
基本角色配置:
角色装饰器.ts
import { SetMetadata } from '@nestjs/common';
export const Roles = (...roles: string[]) => SetMetadata('roles', roles);
Run Code Online (Sandbox Code Playgroud)
角色.guard.ts
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
@Injectable()
export class RolesGuard implements CanActivate {
constructor(private readonly reflector: Reflector) {}
canActivate(context: ExecutionContext): boolean {
const roles = this.reflector.get<string[]>('roles', context.getHandler());
if (!roles) {
return true;
}
const request = context.switchToHttp().getRequest();
const user = …Run Code Online (Sandbox Code Playgroud) 在实现 RedisIoAdapter 如何在https://docs.nestjs.com/websockets/adapter 中进行描述后,我试图将 socket.io-redis 作为调度程序
import { IoAdapter } from '@nestjs/platform-socket.io';
import * as redisIoAdapter from 'socket.io-redis';
export class RedisIoAdapter extends IoAdapter {
createIOServer(port: number, options?: any): any {
const server = super.createIOServer(port, options);
const redisAdapter = redisIoAdapter({ host: 'localhost', port: 6379 });
server.adapter(redisAdapter);
return server;
}
}
Run Code Online (Sandbox Code Playgroud)
出现错误redisIoAdapter此表达式不可调用。
"socket.io-redis": "^6.0.1"
"@nestjs/platform-socket.io": "^7.6.4",
"@nestjs/websockets": "^7.6.4",
Run Code Online (Sandbox Code Playgroud) 我想将文件与 JSON 一起发送
{
"comment" : "string",
"outletId" : 1
}
Run Code Online (Sandbox Code Playgroud)
我从文档中得到的帮助是
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
orderId:
type: integer
userId:
type: integer
fileName:
type: string
format: binary
Run Code Online (Sandbox Code Playgroud)
我不知道把这个架构放在哪里。我曾尝试将其放入@ApiProperty()DTO 以及 中,@ApiOperations但无法解决问题。
下面是我想在其中捕获文件内容的函数。
@Post('/punchin')
@ApiConsumes('multipart/form-data')
@ApiOperation({ summary: 'Attendance Punch In' })
@UseInterceptors(CrudRequestInterceptor, ClassSerializerInterceptor, FileInterceptor('file'))
@ApiImplicitFile({ name: 'file' })
async punchInAttendance( @Body() body: PunchInDto, @UploadedFile() file: Express.Multer.File ): Promise<Attendance> {
const imageUrl = await this.s3FileUploadService.upload(file)
console.log(body, imageUrl)
return await this.service.punchInAttendance({
comment: body.punchInComment,
outletId: body.outletId,
imgUrl: imageUrl, …Run Code Online (Sandbox Code Playgroud) 我在后端 nodejs(nestjs) 上使用。我在登录后从服务器发送 cookie:
res.cookie('token', 'token', {
httpOnly: true
});Run Code Online (Sandbox Code Playgroud)
这是我的 cors 设置app.enableCors({credentials: true });;
作为前端,我使用 reactjs。登录后,服务器将 cookie 发送到这里:

但我需要在这里拿到饼干:
为什么我没有在我展示的地方获取 cookie,以及如何将它们放在那里以保存它们甚至重新加载页面?
先感谢您。我在互联网上搜索了一个工作示例/文档,以获取存储位置点(经度、纬度)、查找两点之间的距离、查找给定距离内的点的方法。我正在使用 typeorm、nestjs、postgresql。
(我已经尝试过 Mariadb,但 St_distance_sphere 在那里不起作用,所以我要使用 postgresql)
这是我的实体
@ApiProperty({
type: String,
title: 'current_location',
example: '{"type":"Point","coordinates":[28.612849, 77.229883]}',
})
@Index({ spatial: true })
@Column({
type: 'geometry',
srid: 4326,
nullable: true,
spatialFeatureType: 'Point',
transformer: {
to: (v: Point) => {
console.log(JSON.stringify(v));
return eval(`ST_GeomFromGeoJSON(${JSON.stringify(v)})`);
},
from: (v: any) => {
return { type: 'Point', coordinates: [v.x, v.y] } as Point;
},
},
})
current_location: string;
Run Code Online (Sandbox Code Playgroud)
似乎有太多的 postgres/postgis 文档,但对我的情况没有任何用处。任何帮助深表感谢。我已经坚持了一个多星期。
*注意:我不想使用 JSONB 数据类型,因为它的速度较慢。
nestjs ×10
node.js ×5
javascript ×3
typescript ×2
express ×1
geojson ×1
graphql ×1
jestjs ×1
jwt ×1
postgresql ×1
reactjs ×1
socket.io ×1
sockets ×1
typeorm ×1
upload ×1