@riocrypto/common-server 1.0.1005 → 1.0.1007

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,8 @@ declare class GoogleSheetsAPIClient {
3
3
  private env;
4
4
  googleAuth: any;
5
5
  constructor(env: RioEnv);
6
- getSheetValues(sheetId: string, range: string): Promise<any[][] | null | undefined>;
7
- getNextAvailableRow(sheetId: string): Promise<string | null | undefined>;
6
+ getNextAvailableRow(sheetId: string): Promise<number>;
7
+ getSheetValues(sheetId: string, rowData: string[]): Promise<void>;
8
8
  }
9
9
  export declare const googleSheetsAPIClient: GoogleSheetsAPIClient;
10
10
  export {};
@@ -19,26 +19,52 @@ class GoogleSheetsAPIClient {
19
19
  scopes: ["https://www.googleapis.com/auth/spreadsheets"],
20
20
  });
21
21
  }
22
- getSheetValues(sheetId, range) {
22
+ getNextAvailableRow(sheetId) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  const authClientObject = yield this.googleAuth.getClient();
25
25
  const sheets = googleapis_1.google.sheets({ version: "v4", auth: authClientObject });
26
26
  const response = yield sheets.spreadsheets.values.get({
27
27
  spreadsheetId: sheetId,
28
- range,
28
+ range: "A:Z", // Adjust the range based on the columns you want to check (e.g., A:Z for columns A to Z)
29
29
  });
30
- return response.data.values;
30
+ const data = response.data.values;
31
+ if (!data || data.length === 0) {
32
+ // If the sheet is completely empty, return the first row (1)
33
+ return 1;
34
+ }
35
+ // Find the first row with empty cells after column A
36
+ for (let i = 0; i < data.length; i++) {
37
+ const row = data[i];
38
+ if (row.length > 1) {
39
+ // If any cell after column A has a value, move to the next row
40
+ continue;
41
+ }
42
+ else {
43
+ // If all cells after column A are empty, return the row number
44
+ return i + 1;
45
+ }
46
+ }
47
+ // If no empty row found, return the next row after the last row
48
+ return data.length + 1;
31
49
  });
32
50
  }
33
- getNextAvailableRow(sheetId) {
51
+ getSheetValues(sheetId, rowData) {
34
52
  return __awaiter(this, void 0, void 0, function* () {
35
53
  const authClientObject = yield this.googleAuth.getClient();
36
54
  const sheets = googleapis_1.google.sheets({ version: "v4", auth: authClientObject });
37
- const response = yield sheets.spreadsheets.values.get({
55
+ const nextAvailableRow = yield this.getNextAvailableRow(sheetId);
56
+ if (nextAvailableRow === -1) {
57
+ throw new Error("Failed to find the next available row.");
58
+ }
59
+ const range = `A${nextAvailableRow}`;
60
+ yield sheets.spreadsheets.values.append({
38
61
  spreadsheetId: sheetId,
39
- range: "A:A",
62
+ range,
63
+ valueInputOption: "USER_ENTERED",
64
+ requestBody: {
65
+ values: [rowData],
66
+ },
40
67
  });
41
- return response.data.range;
42
68
  });
43
69
  }
44
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1005",
3
+ "version": "1.0.1007",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",