How to pick up service object and send to another

Asked

Viewed 8 times

-2

I have the following problem.

I’m working with nestJs and mongodb

I need to store the data of an object, which arrives through an http POST, in two different Clicks from mongoDB.

I’ve tested it individually and I see you’re saving.

But I need to unify that, so that when I trigger this post, it saves that data in these two Points at the same time.

Controller

export class AnalyticsController {
  private services: UnansweredQuestionsService;

  constructor(private service: AnalyticsService) {

  }

  @Post()
  create(@Body() analyticsDto: IAnalytics, unansweredQuestionsDto: IUnansweredQuestions) {
    console.log(analyticsDto);

    let result = analyticsDto;
    console.log("aquiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", result);
    //const result = await new this.integrationModel(obj).save();

    return this.service.save(analyticsDto);
  }

SERVICE

import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { AnalyticsModel, IAnalytics } from 'src/models/analytics.model';
import { unansweredQuestionsModel } from 'src/models/unansweredQuestions.model';
import { UnansweredQuestionsService } from 'src/unansweredQuestions/services/unansweredQuestions.service';
import { UnansweredQuestionsModule } from 'src/unansweredQuestions/unansweredQuestions.module';
import { AnalyticsDTO } from '../../../models/DTO/analytics.dto.model';

@Injectable()
export class AnalyticsService {

  test: any;
  unansweredQuestions: {};

  constructor(
    @InjectModel('reports')
    private integrationModel: Model<AnalyticsModel>,
  ) { }



  async save(obj: IAnalytics) {
    const result = await new this.integrationModel(obj).save();
    if (obj.score == 0) {
      this.unansweredQuestions = result;
      // const resultt = await new unansweredQuestionsModel(this.unansweredQuestions).save();
    }
    return result.id;
  }

service to where I need to send the object

import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { UnansweredQuestionsDTO } from 'src/models/DTO/unansweredQuestions.dto.model';
import { IUnansweredQuestions, unansweredQuestionsModel } from 'src/models/unansweredQuestions.model';
import { AnalyticsService } from 'src/rest-resourses/analytics/services/analytics.service';

@Injectable()
export class UnansweredQuestionsService {

    constructor(
        @InjectModel('unansweredQuestions')
        private unansweredQuestionsModel: Model<unansweredQuestionsModel>
    ) { }

    async save(obj: IUnansweredQuestions) {
        console.log("FOIIIIIII AQUI ÓOOOOOOOOOOOOOOOOOOOOOOOO");
        const result = await new this.unansweredQuestionsModel(obj).save();
        return result.id;
    }

    async savee(obj: AnalyticsService) {

        const result = await new this.unansweredQuestionsModel(obj).save();
        return result.id;
    }

 

I need to send the received object in DTO, to nansweredQuestionsService.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.