Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Store - findOneandDelete Function with Wrong Parameter #94

Open
GerritoMuc opened this issue May 30, 2024 · 0 comments
Open

Generic Store - findOneandDelete Function with Wrong Parameter #94

GerritoMuc opened this issue May 30, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@GerritoMuc
Copy link

Description

The findoneanddelete function returns an error as "options" is not defined. Options needs to be changed to searchParams if I am not wrong.

Original:

    /**
     * Find one entry in the storage using partial of T and delete
     *
     * @param {Partial<T>} searchParams
     * @returns Promise<T>
     */
    findOneAndDelete(searchParams) {
        return __awaiter(this, void 0, void 0, function* () {
            const entities = yield this._getFileContents();
            const match = yield this.findOne(searchParams);
            if (!match)
                throw new Error("DID not found");
            const filtered = entities.filter((e) => {
                let matches = 0;
                for (const key of Object.keys(searchParams)) {
                    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                    // @ts-ignore
                    if (e[key] === options[key])
                        matches++;
                }
                return matches !== Object.keys(searchParams).length;
            });
            yield this._writeFileContents(filtered);
            return match;
        });
    }

Type Of Change

/**
 * Find one entry in the storage using partial of T and delete
 *
 * @param {Partial<T>} searchParams
 * @returns Promise<T>
 */
findOneAndDelete(searchParams) {
    return __awaiter(this, void 0, void 0, function* () {
        const entities = yield this._getFileContents();
        const match = yield this.findOne(searchParams);
        if (!match)
            throw new Error("DID not found");
        const filtered = entities.filter((e) => {
            let matches = 0;
            for (const key of Object.keys(searchParams)) {
                // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                // @ts-ignore
                if (e[key] === searchParams[key])
                    matches++;
            }
            return matches !== Object.keys(searchParams).length;
        });
        yield this._writeFileContents(filtered);
        return match;
    });
}
@GerritoMuc GerritoMuc added the enhancement New feature or request label May 30, 2024
@GerritoMuc GerritoMuc changed the title Generic Store - FindandDelete Function with Wrong Parameter Generic Store - findOneandDelete Function with Wrong Parameter May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant