plenna_utilities 1.3.2 → 1.4.0

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.
@@ -1,10 +1,14 @@
1
1
  import { type docs_v1 } from '@googleapis/docs';
2
- export type documentType = 'text' | 'image';
2
+ export type documentType = 'text' | 'image' | 'deleteRow';
3
3
  export interface ISchemaRequest extends docs_v1.Schema$Request {
4
4
  }
5
5
  export interface IPlennaGoogleBase {
6
6
  doc_type: documentType;
7
- identifier: string;
8
- value: string;
7
+ identifier?: string;
8
+ value?: string;
9
+ rowToDelete?: {
10
+ tableStartLocation?: number;
11
+ rowIndex?: number;
12
+ };
9
13
  }
10
14
  export declare const payloadBuilder: (template: IPlennaGoogleBase[]) => docs_v1.Schema$Request[];
@@ -1,36 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.payloadBuilder = void 0;
4
- const getPayload = (type, variable, value) => {
5
- if (variable === undefined) {
6
- return undefined;
7
- }
8
- if (value === undefined) {
9
- return undefined;
10
- }
11
- const templates = {
12
- text: {
13
- replaceAllText: {
14
- containsText: {
15
- text: `[${variable}]`,
16
- matchCase: true
17
- },
18
- replaceText: value
19
- }
20
- },
21
- image: {
22
- replaceImage: {
23
- imageObjectId: variable,
24
- uri: value
4
+ const getPayload = (type, variable, value, rowToDelete) => {
5
+ if (type === 'deleteRow') {
6
+ if (rowToDelete === undefined) {
7
+ return undefined;
8
+ }
9
+ return {
10
+ deleteTableRow: {
11
+ tableCellLocation: {
12
+ tableStartLocation: {
13
+ index: rowToDelete.tableStartLocation
14
+ },
15
+ rowIndex: rowToDelete.rowIndex
16
+ }
25
17
  }
18
+ };
19
+ }
20
+ else if (['text', 'image'].includes(type)) {
21
+ if (variable === undefined) {
22
+ return undefined;
23
+ }
24
+ if (value === undefined) {
25
+ return undefined;
26
26
  }
27
- };
28
- return templates[type];
27
+ const templates = {
28
+ text: {
29
+ replaceAllText: {
30
+ containsText: {
31
+ text: `[${variable}]`,
32
+ matchCase: true
33
+ },
34
+ replaceText: value
35
+ }
36
+ },
37
+ image: {
38
+ replaceImage: {
39
+ imageObjectId: variable,
40
+ uri: value
41
+ }
42
+ }
43
+ };
44
+ return templates[type];
45
+ }
29
46
  };
30
47
  const payloadBuilder = (template) => {
31
48
  const payload = [];
32
49
  template.forEach(field => {
33
- const val = getPayload(field.doc_type, field.identifier, field.value);
50
+ const val = getPayload(field.doc_type, field.identifier, field.value, field.rowToDelete);
34
51
  if (val !== undefined) {
35
52
  payload.push(val);
36
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plenna_utilities",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "plenna's utils for backend projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",