Skip to content

Conversation

@TorstenDittmann
Copy link
Contributor

@TorstenDittmann TorstenDittmann commented May 31, 2021

  • add typescript definitions
  • add parameter checks

Typescript definition file example: https://gist.github.com/TorstenDittmann/61a1c1fc4fd7f82b823c092a473ebdae

before:

    /**
     * Update Document
     *
     * Update a document by its unique ID. Using the patch method you can pass
     * only specific fields that will get updated.
     *
     * @param string collectionId
     * @param string documentId
     * @param object data
     * @param string[] read
     * @param string[] write
     * @throws Exception
     * @return {}
     */
    async updateDocument(collectionId, documentId, data, read = [], write = []) {
        let path = '/database/collections/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
        
        return await this.client.call('patch', path, {
                    'content-type': 'application/json',
               },
               {
                'data': data,
                'read': read,
                'write': write
            });
    }

after:

    /**
     * Update Document
     *
     * Update a document by its unique ID. Using the patch method you can pass
     * only specific fields that will get updated.
     *
     * @param {string} collectionId
     * @param {string} documentId
     * @param {object} data
     * @param {string[]} read
     * @param {string[]} write
     * @throws {AppwriteException}
     * @returns {Promise}
     */
    async updateDocument(collectionId, documentId, data, read, write) {
        if (typeof collectionId === undefined) {
            throw new AppwriteException('Missing required parameter: "collectionId"');
        }

        if (typeof documentId === undefined) {
            throw new AppwriteException('Missing required parameter: "documentId"');
        }

        if (typeof data === undefined) {
            throw new AppwriteException('Missing required parameter: "data"');
        }

        let path = '/database/collections/{collectionId}/documents/{documentId}'.replace('{collectionId}', collectionId).replace('{documentId}', documentId);
        let payload = {};

        if (typeof data !== undefined) {
            payload['data'] = data;
        }

        if (typeof read !== undefined) {
            payload['read'] = read;
        }

        if (typeof write !== undefined) {
            payload['write'] = write;
        }

        return await this.client.call('patch', path, {
            'content-type': 'application/json',
        }, payload);
    }

@eldadfux eldadfux merged commit d0c455e into master Jun 1, 2021
@lohanidamodar lohanidamodar deleted the fix-node-overall-improvements branch June 5, 2022 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants