Skip to content

Commit b38c15a

Browse files
committed
Add inc/dec
1 parent 1883cbe commit b38c15a

File tree

8 files changed

+136
-3
lines changed

8 files changed

+136
-3
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ jobs:
3939
- name: Publish
4040
run: npm publish --tag ${{ steps.release_tag.outputs.tag }}
4141
env:
42-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_NO_ORG }}

docs/examples/databases/create-document.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Client, Databases } from "react-native-appwrite";
22

33
const client = new Client()
44
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setAdmin('') //
56
.setSession('') // The user session to authenticate with
67
.setKey('') //
78
.setJWT('<YOUR_JWT>'); // Your secret JSON Web Token
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Client, Databases } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const databases = new Databases(client);
8+
9+
const result = await databases.decrementDocumentAttribute(
10+
'<DATABASE_ID>', // databaseId
11+
'<COLLECTION_ID>', // collectionId
12+
'<DOCUMENT_ID>', // documentId
13+
'', // attribute
14+
null, // value (optional)
15+
null // min (optional)
16+
);
17+
18+
console.log(result);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Client, Databases } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const databases = new Databases(client);
8+
9+
const result = await databases.incrementDocumentAttribute(
10+
'<DATABASE_ID>', // databaseId
11+
'<COLLECTION_ID>', // collectionId
12+
'<DOCUMENT_ID>', // documentId
13+
'', // attribute
14+
null, // value (optional)
15+
null // max (optional)
16+
);
17+
18+
console.log(result);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-native-appwrite",
33
"homepage": "https://appwrite.io/support",
44
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5-
"version": "0.10.1",
5+
"version": "0.11.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Client {
115115
'x-sdk-name': 'React Native',
116116
'x-sdk-platform': 'client',
117117
'x-sdk-language': 'reactnative',
118-
'x-sdk-version': '0.10.1',
118+
'x-sdk-version': '0.11.0',
119119
'X-Appwrite-Response-Format': '1.7.0',
120120
};
121121

src/models.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ export namespace Models {
189189
* Document ID.
190190
*/
191191
$id: string;
192+
/**
193+
* Document automatically incrementing ID.
194+
*/
195+
$sequence: number;
192196
/**
193197
* Collection ID.
194198
*/

src/services/databases.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,96 @@ export class Databases extends Service {
256256
'content-type': 'application/json',
257257
}, payload);
258258
}
259+
260+
/**
261+
* Decrement a specific attribute of a document by a given value.
262+
*
263+
* @param {string} databaseId
264+
* @param {string} collectionId
265+
* @param {string} documentId
266+
* @param {string} attribute
267+
* @param {number} value
268+
* @param {number} min
269+
* @throws {AppwriteException}
270+
* @returns {Promise}
271+
*/
272+
decrementDocumentAttribute<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, attribute: string, value?: number, min?: number): Promise<Document> {
273+
if (typeof databaseId === 'undefined') {
274+
throw new AppwriteException('Missing required parameter: "databaseId"');
275+
}
276+
277+
if (typeof collectionId === 'undefined') {
278+
throw new AppwriteException('Missing required parameter: "collectionId"');
279+
}
280+
281+
if (typeof documentId === 'undefined') {
282+
throw new AppwriteException('Missing required parameter: "documentId"');
283+
}
284+
285+
if (typeof attribute === 'undefined') {
286+
throw new AppwriteException('Missing required parameter: "attribute"');
287+
}
288+
289+
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute);
290+
const payload: Payload = {};
291+
292+
if (typeof value !== 'undefined') {
293+
payload['value'] = value;
294+
}
295+
296+
if (typeof min !== 'undefined') {
297+
payload['min'] = min;
298+
}
299+
300+
const uri = new URL(this.client.config.endpoint + apiPath);
301+
return this.client.call('patch', uri, {
302+
'content-type': 'application/json',
303+
}, payload);
304+
}
305+
306+
/**
307+
* Increment a specific attribute of a document by a given value.
308+
*
309+
* @param {string} databaseId
310+
* @param {string} collectionId
311+
* @param {string} documentId
312+
* @param {string} attribute
313+
* @param {number} value
314+
* @param {number} max
315+
* @throws {AppwriteException}
316+
* @returns {Promise}
317+
*/
318+
incrementDocumentAttribute<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, attribute: string, value?: number, max?: number): Promise<Document> {
319+
if (typeof databaseId === 'undefined') {
320+
throw new AppwriteException('Missing required parameter: "databaseId"');
321+
}
322+
323+
if (typeof collectionId === 'undefined') {
324+
throw new AppwriteException('Missing required parameter: "collectionId"');
325+
}
326+
327+
if (typeof documentId === 'undefined') {
328+
throw new AppwriteException('Missing required parameter: "documentId"');
329+
}
330+
331+
if (typeof attribute === 'undefined') {
332+
throw new AppwriteException('Missing required parameter: "attribute"');
333+
}
334+
335+
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute);
336+
const payload: Payload = {};
337+
338+
if (typeof value !== 'undefined') {
339+
payload['value'] = value;
340+
}
341+
342+
if (typeof max !== 'undefined') {
343+
payload['max'] = max;
344+
}
345+
346+
const uri = new URL(this.client.config.endpoint + apiPath);
347+
return this.client.call('patch', uri, {
348+
'content-type': 'application/json',
349+
}, payload);
350+
}
259351
};

0 commit comments

Comments
 (0)