baqend, problem encountered while storing information in database

Hey there,
I'm facing an issue with saving data to my database and I can't seem to figure out the problem. The QueryBuilder for And-, Or-, and OrAnd-Select seems to be identical in code. I've written the QueryBuilder for And-select, Or-select, and OrAnd-select in that specific order consecutively.

However, while saving data works perfectly fine for And-select and OR-select, it fails for OrAnd-select. As you can see in the image provided, the data doesn't get saved in the database User_DataDb successfully. Any help would be appreciated!

Thanks a lot in advance.

View the image description here

I keep getting this error:

EXCEPTION: Uncaught (in promise): Error: Current operation has not been finished.
withLock@http://localhost:3000/main.bundle.js:21238:31 [angular]
_save@http://localhost:3000/main.bundle.js:11260:12 [angular]
update@http://localhost:3000/main.bundle.js:11097:12 [angular]
update@http://localhost:3000/main.bundle.js:12956:14 [angular]
ac_main</NoSqlComponent.prototype.submit/promise</</<@http://localhost:3000/main.bundle.js:29457:21 [angular]
onInvoke@http://localhost:3000/vendor.dll.js:30326:28 [angular]
polyfills_lib</</</Zone.prototype.run@http://localhost:3000/polyfills.dll.js:4133:24 [angular => angular]
scheduleResolveOrReject/<@http://localhost:3000/polyfills.dll.js:4720:52 [angular]
onInvokeTask@http://localhost:3000/vendor.dll.js:30317:28 [angular]
polyfills_lib</</</ZoneDelegate.prototype.invokeTask@http://localhost:3000/polyfills.dll.js:4373:17 [angular]
polyfills_lib</</</Zone.prototype.runTask@http://localhost:3000/polyfills.dll.js:4173:28 [<root> => angular]
drainMicroTaskQueue@http://localhost:3000/polyfills.dll.js:4553:25 [<root>]
ZoneTask/this.invoke@http://localhost:3000/polyfills.dll.js:4431:25 [<root>]

This is my code snippet

/////////////// queryBuilder for And-Select
        var queryBuilderAnd = db.NoSqlDB.find();
        var techniques = queryBuilderAnd
            .in('techniques', this.arrStrTchn);
        var functional = queryBuilderAnd
            .in('functional', this.arrStrFn);
        var nonFunctional = queryBuilderAnd
            .in('nonFunctional', this.arrStrNFn);
        var promiseAnd = queryBuilderAnd.and(techniques, functional, nonFunctional)
            .resultList()
            .then((nosqlDbAnd) => {
                console.log(nosqlDbAnd);

                this.nosqlDbsAnd = nosqlDbAnd;
                console.log("this.nosqlDbsAnd ", this.nosqlDbsAnd);

                this.nosqlDbsAnd.forEach(
                    (and) => {
                        console.log("and: " + and.id);
                        db.NoSqlDB.find()
                            .equal('id', and.id)
                            .resultList((result) => {
                                result.forEach((todo) => {
                                    and.select_and = JSON.parse(JSON.stringify(this.andselected));
                                    if (and.users_and === null) {
                                        and.users_and = new Set();
                                    }
                                    and.users_and.add(db.User.me);
                                    return and.update();
                                });
                            });
     new db.User_DataDb(
         {
          functional_select: this.functionalCatObj, nonfunctional_select: this.nfunctionalCatObj,
          techniques_select: this.techniquesCatObj, functional_unselect: this.functionalUnsCatObj,
          nonfunctional_unselect: this.nfunctionalCatObj, techniques_unselect: this.techniquesUnsCatObj,
          ref_NosqlDbAnd: [and.id]

           }).insert()
                    .then((todo1) => {
                     console.log("todo1.id: ", todo1.id);
                     db.User_DataDb.find()
                          .where({
                                'ref_NosqlDbAnd': and.id,
                                'id': todo1.id
                            })
                            .resultList((result) => {
                                result.forEach(
                                    (todo2) => {
                                        if (todo2.user_and === null) {
                                            todo2.user_and = new Set();
                                        }

                                        todo2.user_and.add(db.User.me);
                                        return todo2.save({ refresh: true });
                                    });
                            });
                    });
            });
      });    

/////////////// queryBuilder for OR-Select
        var queryBuilderOr = db.NoSqlDB.find();
        var techniques = queryBuilderOr
            .in('techniques', this.arrStrTchn);
        var functional = queryBuilderOr
            .in('functional', this.arrStrFn);
        var nonFunctional = queryBuilderOr
            .in('nonFunctional', this.arrStrNFn);
        var promiseOr = queryBuilderOr.or(techniques, functional, nonFunctional)
            .resultList()
            .then((nosqlDbOr) => {
                console.log(nosqlDbOr);

                this.nosqlDbsOr = nosqlDbOr;
                console.log("this.nosqlDbsOr ", this.nosqlDbsOr);

                this.nosqlDbsOr.forEach(
                    (or) => {

                        db.NoSqlDB.find()
                            .equal('id', or.id)
                            .resultList((result) => {
                                result.forEach((todo) => {
                                    or.select_or = JSON.parse(JSON.stringify(this.orselected));
                                    if (or.users_or === null) {
                                        or.users_or = new Set();
                                    }
                                    or.users_or.add(db.User.me);

                                    return or.update();
                                });
                            });
     new db.User_DataDb(
         {
          functional_select: this.functionalCatObj, nonfunctional_select: this.nfunctionalCatObj,
          techniques_select: this.techniquesCatObj, functional_unselect: this.functionalUnsCatObj,
          nonfunctional_unselect: this.nfunctionalCatObj, techniques_unselect: this.techniquesUnsCatObj,
          ref_NosqlDbOr: [or.id]

           }).insert()
                    .then((todo1) => {
                     console.log("todo1.id: ", todo1.id);
                     db.User_DataDb.find()
                          .where({
                                'ref_NosqlDbOr': or.id,
                                'id': todo1.id
                            })
                            .resultList((result) => {
                                result.forEach(
                                    (todo2) => {
                                        if (todo2.user_or === null) {
                                            todo2.user_or = new Set();
                                        }

                                        todo2.user_or.add(db.User.me);
                                        return todo2.save({ refresh: true });
                                    });
                            });
                    });
            });
      });    

Answer №1

The root of the issue lies in attempting to modify an object while simultaneously saving it. It's crucial to ensure that modifications and saves are performed on the same object sequentially.

Furthermore, loading objects that have already been loaded is redundant:

let promiseOr = queryBuilderOr.or(techniques, functional, nonFunctional)
    .resultList()
    .then((nosqlDbOr) => {
        console.log(nosqlDbOr);
        this.nosqlDbsOr = nosqlDbOr;
        console.log("this.nosqlDbsOr ", this.nosqlDbsOr);

        this.nosqlDbsOr.forEach((or) => {
            // Avoid unnecessary db.NoSqlDB.find() calls as the object is already loaded

            if (and.users_or === null) {
                and.users_or = new Set();
            }
            or.users_or.add(db.User.me);

            // Prevent updating the same object multiple times in different queries' callbacks
            return or.update();
        });
    });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can TypeScript be configured to recognize the generic object assignment illustrated below?

Take a look at this code snippet: type Type = 'one' | 'two' | 'three' type TypeSelection = 'one' | 'two' interface InnerObject<T extends Type> { name: string, type: T } type Obj<K extends Ty ...

The error states that the type '() => string | JSX.Element' cannot be assigned to the type 'FC<{}>'

Can someone help me with this error I'm encountering? I am fairly new to typescript, so I assume it has something to do with that. Below is the code snippet in question: Any guidance would be greatly appreciated. const Pizzas: React.FC = () => { ...

Using RxJS switchMap in combination with toArray allows for seamless transformation

I'm encountering an issue with rxjs. I have a function that is supposed to: Take a list of group IDs, such as: of(['1', '2']) Fetch the list of chats for each ID Return a merged list of chats However, when it reaches the toArray ...

What is the best way to programmatically generate a service within Angular?

Is there a way to dynamically create services at runtime using a string name (like reflection)? For example: let myService = new window[myClassName](myParams); Alternatively, you could try: let myService = Object.create(window[myClassName].prototype); m ...

Discovering the proper way to namespace or target a variable input within a component

Consider the following: mat-button directive is affected by a disabled attribute / input. matTooltip directive is also impacted by a disabled attribute / input. Can you design a material button that appears disabled, but still has an active tooltip asso ...

How can data be transferred from a parent to a child component in Angular?

I'm facing an issue trying to pass the selected value from a dropdownlist in a user interface. I have a parent component (app.component.html) and a child component (hello.component.html & hello.component.ts). My goal is to transfer the option val ...

Obtaining the TemplateRef from any HTML Element in Angular 2

I am in need of dynamically loading a component into an HTML element that could be located anywhere inside the app component. My approach involves utilizing the TemplateRef as a parameter for the ViewContainerRef.createEmbeddedView(templateRef) method to ...

Issue: AdonisJS is encountering an error that prevents it from reading properties of undefined (specifically the 'get' property) when attempting to enable

Recently, I started using Adonisjs for building my REST API. However, when I enabled the csrf in ShieldConfig, I encountered the following error: "type": "TypeError", "message": "Cannot read properties of undefined (rea ...

Exploring the potential of Angular2's WebSocket service by efficiently accessing the parent component

I need some assistance with implementing WebSockets in my angular2 application. However, I've encountered a minor issue that I can't seem to solve. Here's what I have so far: I've created a service that has a method for creating a WebS ...

How can you automate the process of skipping a protractor test?

Is there a way to skip protractor test cases based on certain conditions being true or false? I tried using pending('skipped'); expect(true).toBe(true); But it is marked as failed. Update I found a way to add test cases to "Pen ...

The JsonFormatter is throwing an error because it is trying to access the property 'on' of an undefined variable

I have encountered an error while attempting to generate an HTML report using cucumber-html-reporter The error message is: Unhandled rejection TypeError: Cannot read property 'on' of undefined at new JsonFormatter (C:\path-to-project\ ...

Before the device is fully ready, the ionViewWillEnter event in Ionic 4 tab is triggered

In my app's app.components.ts file, I have the initializeApp code within the constructor as shown below: app.components.ts constructor( private platform: Platform, private splashScreen: SplashScreen, private statusBar: StatusBar, ) ...

Retrieve the additional navigation information using Angular's `getCurrentNavigation()

I need to pass data along with the route from one component to another and retrieve it in the other component's constructor: Passing data: this.router.navigate(['/coaches/list'], { state: { updateMessage: this.processMessage }, ...

Refining a Collection of Possible Options

If I have an array of type Maybe<int>[] and want to extract only the values that are not None, what is the most efficient approach while ensuring TypeScript recognizes the output as int[]? It seems like declaring the result type as int[] is the way ...

What is the reason behind `ngAfterViewChecked` and `ngAfterContentChecked` being invoked twice?

import { AfterContentChecked, AfterViewChecked, Component } from '@angular/core'; @Component({ selector: 'app-root', template: '' }) export class AppComponent implements AfterViewChecked, AfterContentChecked { ngA ...

Incapable of adding a singular string to an array without altering the string's original value

Introducing the edit-customer component, a dialog window designed to receive an injected object from another component and display its properties, such as name and email. Below is the code for this component: HTML <form [formGroup]="editForm"> ...

How can I extract data from the 'ngx-quill' editor when integrating it with a FormBuilder in Angular?

After implementing the 'ngx-quill' editor package in my Angular 15 project, I encountered an issue where the value of the content form control was returning 'null' upon form submission using FormBuilder. Despite entering text such as he ...

The "my-app" selector in Angular2 did not find any elements upon initial loading

Has anyone encountered this error upon the initial page load in their Angular2 app? It disappears upon navigating through the app, but sometimes reappears if I refresh with CTRL+F5. The routing structure of my app is as follows: AppComponent.ts LoginCom ...

The statement 'typeof import("...")' fails to meet the requirement of 'IEntry' constraint

When trying to run npm run build for my NextJS 13 app, I encountered the following type error: Type error: Type 'typeof import("E:/myapp/app/login/page")' does not satisfy the constraint 'IEntry'. Types of property 'def ...

Error TS2305: The module "@prisma/client" does not have an export named "User"

Setting up a Gitlab CI for my nestjs project using prisma has been my current challenge. I keep encountering this error when running the pipeline: see image here This is what my .gitlab-ci.yml looks like: image: node:latest stages: - build build: st ...