小编Yar*_*ron的帖子

如何开玩笑模拟 Nestjs 导入?

我想为我的 Nestjs“课程”存储库服务(依赖于 Mongoose 模型和 Redis 的服务)编写一个单元测试。

课程.存储库.ts:

    import { Injectable, HttpException, NotFoundException } from "@nestjs/common";
    import { InjectModel } from "@nestjs/mongoose"
    import { Course } from "../../../../shared/course";
    import { Model } from "mongoose";
    import { RedisService } from 'nestjs-redis';


    @Injectable({}) 
    export class CoursesRepository {

      private redisClient;
      constructor(
        @InjectModel('Course') private courseModel: Model<Course>,
        private readonly redisService: RedisService,
      ) {
        this.redisClient = this.redisService.getClient();

      }


      async findAll(): Promise<Course[]> {
        const courses = await this.redisClient.get('allCourses');
        if (!courses) {
          console.log('return from DB');
          const mongoCourses = await …
Run Code Online (Sandbox Code Playgroud)

unit-testing node.js typescript jestjs nestjs

8
推荐指数
2
解决办法
2万
查看次数

如何在 nestjs 中填充猫鼬引用?

我定义了一个人和故事模式:

    @Schema()
    export class Person extends Document {
      @Prop()
      name: string;
    }
    export const PersonSchema = SchemaFactory.createForClass(Person);
    
    
    @Schema()
    export class Story extends Document {
    
      @Prop()
      title: string;
    
      @Prop()
      author:  { type: MongooseSchema.Types.ObjectId , ref: 'Person' }
    
    }
    export const StorySchema = SchemaFactory.createForClass(Story);
Run Code Online (Sandbox Code Playgroud)

在我的服务中,我实现了保存和读取功能:

        async saveStory(){
        const newPerson = new this.personModel();
        newPerson.name  = 'Ian Fleming';
        await newPerson.save();
        const newStory  = new this.storyModel();
        newStory.title = 'Casino Royale';
        newStory.author = newPerson._id;
        await newStory.save();
      }
    
      async readStory(){
        const stories = await this.storyModel.
            findOne({ title: …
Run Code Online (Sandbox Code Playgroud)

mongoose mongoose-populate nestjs

7
推荐指数
2
解决办法
4991
查看次数

Laravel 中的大量更新(Eloquent)

有没有办法在 Laravel(MySQL 数据库)中批量插入(插入或更新,如果存在)记录?

假设我有一张桌子:

[id:1 value:4]
[id:2 value:5]
Run Code Online (Sandbox Code Playgroud)

我想执行:

Model::massupsert([
  [id:1 value:100],
  [id:3 value:20]
]);
Run Code Online (Sandbox Code Playgroud)

之后的表格是:

[id:1 value:100]
[id:2 value:5]
[id:3 value:20]
Run Code Online (Sandbox Code Playgroud)

laravel eloquent

5
推荐指数
2
解决办法
4718
查看次数

如何从 React Material UI 中的基色创建颜色变体?

我的主题中有一个给定的颜色常量,比如说“#FFBA60”。

我想使用 React Material UI 函数从其他一些基本颜色中派生出来。(假设一个亮 30%,一个暗 10%)。

有这个功能吗?(类似于 Sass brighten('#FFBA60,30%)

reactjs material-ui

5
推荐指数
3
解决办法
2547
查看次数

反应原生事件

我有一个TextInput组件调用'OnChangeText'事件:

<TextInput onChangeText={(text) => this.setState({zip:text})}/>
Run Code Online (Sandbox Code Playgroud)

这很好.

现在我想将call事件更改为函数:

 <TextInput onChangeText={_handleTextChange}/>

_handleTextChange(event) {
       this.setState({zip: 
       event.nativeEvent.text});

  }
Run Code Online (Sandbox Code Playgroud)

这不起作用.我收到以下错误:

undefined不是对象(评估'event.nativeEvent.text'

如何将'Event'对象发送到_handleTextChange函数?

谢谢你,亚伦

reactjs react-native

2
推荐指数
1
解决办法
7934
查看次数

在Sequelize中更新计算值

我想使用一个字段中的先前值在模型上运行更新查询。

这会将模型(行ID = 4)的“ seq”字段更新为5。

 Model.update({
        seq: 5
    },{
        where:{
            'id':4,

        }
    });
Run Code Online (Sandbox Code Playgroud)

现在如何将模型更新为存储在“ seq”字段中的先前值+ 5?

 Model.update({
            seq: 'seq' + 5
        },{
            where:{
                'id':4,

            }
        });
Run Code Online (Sandbox Code Playgroud)

node.js sequelize.js

0
推荐指数
3
解决办法
457
查看次数