async updateResource()

in src/dataServices/dynamoDbDataService.ts [187:221]


    async updateResource(request: UpdateResourceRequest) {
        this.assertValidTenancyMode(request.tenantId);
        const { resource, resourceType, id, tenantId } = request;
        try {
            // Will throw ResourceNotFoundError if resource can't be found
            await this.readResource({ resourceType, id, tenantId });
        } catch (e) {
            if (this.updateCreateSupported && isResourceNotFoundError(e)) {
                return this.createResourceWithId(resourceType, resource, id, tenantId);
            }
            throw e;
        }
        const resourceClone = clone(resource);
        const batchRequest: BatchReadWriteRequest = {
            operation: 'update',
            resourceType,
            id,
            resource: resourceClone,
        };

        // Sending the request to `atomicallyReadWriteResources` to take advantage of LOCKING management handled by
        // that method
        const response: BundleResponse = await this.transactionService.transaction({
            requests: [batchRequest],
            startTime: new Date(),
            tenantId,
        });
        const batchReadWriteEntryResponse = response.batchReadWriteResponses[0];
        resourceClone.meta = batchReadWriteEntryResponse.resource.meta;
        return {
            success: true,
            message: 'Resource updated',
            resource: resourceClone,
        };
    }