mp-js-api 0.0.2 → 0.0.4
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.
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -2
- package/dist/tables/form-responses.d.ts +49 -0
- package/dist/tables/form-responses.d.ts.map +1 -0
- package/dist/tables/form-responses.js +2 -0
- package/dist/tables/from-response-answers.d.ts +21 -0
- package/dist/tables/from-response-answers.d.ts.map +1 -0
- package/dist/tables/from-response-answers.js +2 -0
- package/dist/utils/strings.d.ts +5 -0
- package/dist/utils/strings.d.ts.map +1 -1
- package/dist/utils/strings.js +41 -0
- package/package.json +2 -2
- package/src/index.ts +26 -5
- package/src/tables/form-responses.ts +51 -0
- package/src/tables/from-response-answers.ts +25 -0
- package/src/utils/strings.ts +45 -0
package/dist/index.d.ts
CHANGED
|
@@ -8,14 +8,16 @@ import { Group } from './tables/groups';
|
|
|
8
8
|
import { Household } from './tables/households';
|
|
9
9
|
import { Address } from './tables/addresses';
|
|
10
10
|
import { ContactAttribute } from './tables/contact-attributes';
|
|
11
|
+
import { FormResponse } from './tables/form-responses';
|
|
11
12
|
type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
12
|
-
export type CreateContactParams = WithRequired<Partial<Contact>, 'company' | 'displayName'>;
|
|
13
|
+
export type CreateContactParams = WithRequired<Omit<Partial<Contact>, 'contactID'>, 'company' | 'displayName'>;
|
|
13
14
|
export type CreateHouseholdParams = WithRequired<Partial<Household>, 'householdName'>;
|
|
14
15
|
export type CreateAddressParams = WithRequired<Partial<Address>, 'addressLine1'>;
|
|
15
16
|
export type CreateParticipantParams = WithRequired<Partial<Participant>, 'contactID' | 'participantTypeID' | 'participantStartDate'>;
|
|
16
17
|
export type CreateEventParticipantParams = WithRequired<Partial<EventParticipant>, 'eventID' | 'participantID' | 'participationStatusID'>;
|
|
17
18
|
export type CreateGroupParticipantParams = WithRequired<Partial<GroupParticipant>, 'groupID' | 'participantID' | 'groupRoleID' | 'startDate'>;
|
|
18
19
|
export type CreateContactAttributeParams = WithRequired<Partial<ContactAttribute>, 'attributeID' | 'contactID' | 'startDate'>;
|
|
20
|
+
export type CreateFormResponseParams = WithRequired<Omit<Partial<FormResponse>, 'formResponseID'>, 'formID' | 'responseDate'>;
|
|
19
21
|
export type MPGetOptions = {
|
|
20
22
|
select?: string;
|
|
21
23
|
filter?: string;
|
|
@@ -103,6 +105,9 @@ export type MPInstance = {
|
|
|
103
105
|
createContactAttribute(params: CreateContactAttributeParams, options?: MPCreateOptions): Promise<ContactAttribute | {
|
|
104
106
|
error: any;
|
|
105
107
|
}>;
|
|
108
|
+
createFormResponse(params: CreateFormResponseParams, options?: MPCreateOptions): Promise<FormResponse | {
|
|
109
|
+
error: any;
|
|
110
|
+
}>;
|
|
106
111
|
updateContacts(contacts: WithRequired<Partial<Contact>, 'contactID'>[], options?: MPUpdateOptions): Promise<Contact[] | {
|
|
107
112
|
error: any;
|
|
108
113
|
}>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEhF,OAAO,EAAE,OAAO,EAA6B,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAsC,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAgD,MAAM,6BAA6B,CAAC;AAC7G,OAAO,EAAE,gBAAgB,EAAgD,MAAM,6BAA6B,CAAC;AAC7G,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAaxC,OAAO,EAAE,SAAS,EAAuE,MAAM,qBAAqB,CAAC;AACrH,OAAO,EAAE,OAAO,EAA8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,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,EACvD,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,GAAG;QAAE,KAAK,EAAE,GAAG,CAAC;KAAE,CAAC,CAAC;IAExC,uBAAuB,CACrB,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC,EAAE,EAC7E,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,EAAE,GAAG;QAAE,KAAK,EAAE,GAAG,CAAC;KAAE,CAAC,CAAC;CAClD,CAAC;AAYF,eAAO,MAAM,gBAAgB,aAAc;IAAE,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;KAAE,CAAC;CAAE,KAAG,UA4V/F,CAAC;AAEF,OAAO,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,gBAAgB,EACjB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -113,7 +113,7 @@ const createMPInstance = ({ auth }) => {
|
|
|
113
113
|
async getAddress(id, options = {}) {
|
|
114
114
|
try {
|
|
115
115
|
const res = await get(`/tables/addresses/${id}`, options);
|
|
116
|
-
return res.data[0] ? (0,
|
|
116
|
+
return res.data[0] ? (0, strings_1.convertToCamelCase)(res.data[0]) : undefined;
|
|
117
117
|
}
|
|
118
118
|
catch (err) {
|
|
119
119
|
return { error: err };
|
|
@@ -133,7 +133,7 @@ const createMPInstance = ({ auth }) => {
|
|
|
133
133
|
async getEvent(id, options = {}) {
|
|
134
134
|
try {
|
|
135
135
|
const res = await get(`/tables/events/${id}`, options);
|
|
136
|
-
return res.data[0] ? (0,
|
|
136
|
+
return res.data[0] ? (0, strings_1.convertToCamelCase)(res.data[0]) : undefined;
|
|
137
137
|
}
|
|
138
138
|
catch (err) {
|
|
139
139
|
return { error: err };
|
|
@@ -318,6 +318,18 @@ const createMPInstance = ({ auth }) => {
|
|
|
318
318
|
return { error: err };
|
|
319
319
|
}
|
|
320
320
|
},
|
|
321
|
+
async createFormResponse(params, options = {}) {
|
|
322
|
+
const query = stringifyMPOptions(options);
|
|
323
|
+
try {
|
|
324
|
+
const res = await post(`/tables/form_responses${query}`, [
|
|
325
|
+
(0, strings_1.convertToSnakeCase)(params)
|
|
326
|
+
]);
|
|
327
|
+
return (0, strings_1.convertToCamelCase)(res.data[0]);
|
|
328
|
+
}
|
|
329
|
+
catch (err) {
|
|
330
|
+
return { error: err };
|
|
331
|
+
}
|
|
332
|
+
},
|
|
321
333
|
async updateContacts(contacts, options = {}) {
|
|
322
334
|
const query = stringifyMPOptions(options);
|
|
323
335
|
try {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface FormResponseRecord {
|
|
2
|
+
Form_Response_ID: number;
|
|
3
|
+
Form_ID: number;
|
|
4
|
+
Response_Date: string;
|
|
5
|
+
IP_Address: string | null;
|
|
6
|
+
Contact_ID: number;
|
|
7
|
+
First_Name: string;
|
|
8
|
+
Last_Name: string;
|
|
9
|
+
Email_Address: string | null;
|
|
10
|
+
Phone_Number: string | null;
|
|
11
|
+
Address_Line_1: string | null;
|
|
12
|
+
Address_Line_2: string | null;
|
|
13
|
+
Address_City: string | null;
|
|
14
|
+
Address_State: string | null;
|
|
15
|
+
Address_Zip: number | null;
|
|
16
|
+
Event_ID: number;
|
|
17
|
+
Pledge_Campaign_ID: null;
|
|
18
|
+
Opportunity_ID: null;
|
|
19
|
+
Opportunity_Response: null;
|
|
20
|
+
Congregation_ID: number;
|
|
21
|
+
Notification_Sent: boolean;
|
|
22
|
+
Expires: null;
|
|
23
|
+
Event_Participant_ID: number | null;
|
|
24
|
+
}
|
|
25
|
+
export interface FormResponse {
|
|
26
|
+
formResponseID: number;
|
|
27
|
+
formID: number;
|
|
28
|
+
responseDate: string;
|
|
29
|
+
iPAddress: string | null;
|
|
30
|
+
contactID: number;
|
|
31
|
+
firstName: string;
|
|
32
|
+
lastName: string;
|
|
33
|
+
emailAddress: string | null;
|
|
34
|
+
phoneNumber: string | null;
|
|
35
|
+
addressLine1: string | null;
|
|
36
|
+
addressLine2: string | null;
|
|
37
|
+
addressCity: string | null;
|
|
38
|
+
addressState: string | null;
|
|
39
|
+
addressZip: number | null;
|
|
40
|
+
eventID: number;
|
|
41
|
+
pledgeCampaignID: null;
|
|
42
|
+
opportunityID: null;
|
|
43
|
+
opportunityResponse: null;
|
|
44
|
+
congregationID: number;
|
|
45
|
+
notificationSent: boolean;
|
|
46
|
+
expires: null;
|
|
47
|
+
eventParticipantID: number | null;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=form-responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-responses.d.ts","sourceRoot":"","sources":["../../src/tables/form-responses.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,kBAAkB;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,EAAE,MAAM,GAAE,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,IAAI,CAAC;IACzB,cAAc,EAAE,IAAI,CAAC;IACrB,oBAAoB,EAAE,IAAI,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,OAAO,EAAE,IAAI,CAAC;IACd,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAGD,MAAM,WAAW,YAAY;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAE,IAAI,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,IAAI,CAAC;IACvB,aAAa,EAAE,IAAI,CAAC;IACpB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,IAAI,CAAC;IACd,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface FormResponseAnswerRecord {
|
|
2
|
+
Form_Response_Answer_ID: number;
|
|
3
|
+
Form_Field_ID: number;
|
|
4
|
+
Response: string | null;
|
|
5
|
+
Form_Response_ID: number;
|
|
6
|
+
Event_Participant_ID: number | null;
|
|
7
|
+
Pledge_ID: null;
|
|
8
|
+
Opportunity_Response: null;
|
|
9
|
+
Placed: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface FormResponseAnswer {
|
|
12
|
+
form_Response_Answer_ID: number;
|
|
13
|
+
form_Field_ID: number;
|
|
14
|
+
response: string | null;
|
|
15
|
+
form_Response_ID: number;
|
|
16
|
+
event_Participant_ID: number | null;
|
|
17
|
+
pledge_ID: null;
|
|
18
|
+
opportunity_Response: null;
|
|
19
|
+
placed: boolean;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=from-response-answers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-response-answers.d.ts","sourceRoot":"","sources":["../../src/tables/from-response-answers.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,wBAAwB;IACxC,uBAAuB,EAAE,MAAM,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,SAAS,EAAE,IAAI,CAAC;IAChB,oBAAoB,EAAE,IAAI,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;CAChB;AAID,MAAM,WAAW,kBAAkB;IAClC,uBAAuB,EAAE,MAAM,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,SAAS,EAAE,IAAI,CAAC;IAChB,oBAAoB,EAAE,IAAI,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;CAChB"}
|
package/dist/utils/strings.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare function escapeSql(str: string): string;
|
|
2
|
+
export declare function toCamelCase(str: string): string;
|
|
3
|
+
export declare function toCapitalSnakeCase(str: string): string;
|
|
4
|
+
export declare function caseConverter<T>(obj: T, type: 'toCamel' | 'toSnake'): any;
|
|
5
|
+
export declare function convertToCamelCase<T = any, R = any>(obj: T): R;
|
|
6
|
+
export declare function convertToSnakeCase<T = any, R = any>(obj: T): R;
|
|
2
7
|
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UA2BpC"}
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UA2BpC;AAID,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,UAKtC;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,UAK7C;AAGD,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,GAAG,SAAS,OAkBnE;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAE9D;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAE9D"}
|
package/dist/utils/strings.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.escapeSql = escapeSql;
|
|
4
|
+
exports.toCamelCase = toCamelCase;
|
|
5
|
+
exports.toCapitalSnakeCase = toCapitalSnakeCase;
|
|
6
|
+
exports.caseConverter = caseConverter;
|
|
7
|
+
exports.convertToCamelCase = convertToCamelCase;
|
|
8
|
+
exports.convertToSnakeCase = convertToSnakeCase;
|
|
4
9
|
function escapeSql(str) {
|
|
5
10
|
return str.replace(/%|(?<=\w)'(?=\w)/g, function (char) {
|
|
6
11
|
switch (char) {
|
|
@@ -29,3 +34,39 @@ function escapeSql(str) {
|
|
|
29
34
|
}
|
|
30
35
|
});
|
|
31
36
|
}
|
|
37
|
+
function toCamelCase(str) {
|
|
38
|
+
str = str.replace(/((?<=^_|^__))[^\W_]/g, match => match.at(-1)?.toLowerCase() || ''); // keep underscore if first char
|
|
39
|
+
str = str.replace(/(?<!^_|^)_[^\W_]/g, match => match.charAt(1).toUpperCase()); // remove underscore if not first char
|
|
40
|
+
str = str.charAt(0).toLowerCase() + str.slice(1);
|
|
41
|
+
return str.replace(/id$/i, 'ID');
|
|
42
|
+
}
|
|
43
|
+
function toCapitalSnakeCase(str) {
|
|
44
|
+
str = str.replace(/(?<=^_|^__)[^\W_]/, match => match.at(0)?.toUpperCase() || '');
|
|
45
|
+
str = str.replace(/(?<!_|\/)(ID|[A-Z])/g, match => `_${match}`);
|
|
46
|
+
str = str.charAt(0).toUpperCase() + str.slice(1);
|
|
47
|
+
return str.replace(/_id$/i, '_ID');
|
|
48
|
+
}
|
|
49
|
+
// Function to recursively convert object keys to Capital_Snake_Case
|
|
50
|
+
function caseConverter(obj, type) {
|
|
51
|
+
const caseFn = type === 'toCamel' ? toCamelCase : toCapitalSnakeCase;
|
|
52
|
+
if (Array.isArray(obj)) {
|
|
53
|
+
return obj.map(val => caseConverter(val, type)); // Recursively process each array element
|
|
54
|
+
}
|
|
55
|
+
if (obj !== null && typeof obj === 'object') {
|
|
56
|
+
const snakeCaseObj = {};
|
|
57
|
+
for (const key in obj) {
|
|
58
|
+
if (obj.hasOwnProperty(key)) {
|
|
59
|
+
const snakeCaseKey = caseFn(key); // Convert key to Snake_Case
|
|
60
|
+
snakeCaseObj[snakeCaseKey] = caseConverter(obj[key], type); // Recursively process nested objects
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return snakeCaseObj;
|
|
64
|
+
}
|
|
65
|
+
return obj; // Return value if it's neither an array nor an object
|
|
66
|
+
}
|
|
67
|
+
function convertToCamelCase(obj) {
|
|
68
|
+
return caseConverter(obj, 'toCamel');
|
|
69
|
+
}
|
|
70
|
+
function convertToSnakeCase(obj) {
|
|
71
|
+
return caseConverter(obj, 'toSnake');
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mp-js-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Node MinistryPlatform API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "mocha --require ts-node/register test/*",
|
|
8
|
-
"
|
|
8
|
+
"compile": "tsc"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [],
|
|
11
11
|
"author": "",
|
package/src/index.ts
CHANGED
|
@@ -21,7 +21,8 @@ import { mapGroupParticipantRecord } from './tables/group-participants';
|
|
|
21
21
|
import { Household, HouseholdRecord, mapHouseholdRecord, mapHouseholdToHouseholdRecord, } from './tables/households';
|
|
22
22
|
import { Address, AddressRecord, mapAddressRecord, mapAddressToAddressRecord } from './tables/addresses';
|
|
23
23
|
import { ContactAttribute, ContactAttributeRecord, mapContactAttributeRecord, mapContactAttributeToContactAttributeRecord } from './tables/contact-attributes';
|
|
24
|
-
import { escapeSql } from './utils/strings';
|
|
24
|
+
import { convertToCamelCase, convertToSnakeCase, escapeSql } from './utils/strings';
|
|
25
|
+
import { FormResponse, FormResponseRecord } from './tables/form-responses';
|
|
25
26
|
|
|
26
27
|
interface TokenData {
|
|
27
28
|
access_token: string;
|
|
@@ -70,7 +71,7 @@ const createTokenGetter = (auth: { username: string; password: string; }) => {
|
|
|
70
71
|
type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
71
72
|
|
|
72
73
|
export type CreateContactParams = WithRequired<
|
|
73
|
-
Partial<Contact>,
|
|
74
|
+
Omit<Partial<Contact>, 'contactID'>,
|
|
74
75
|
'company' | 'displayName'
|
|
75
76
|
>;
|
|
76
77
|
export type CreateHouseholdParams = WithRequired<
|
|
@@ -97,6 +98,10 @@ export type CreateContactAttributeParams = WithRequired<
|
|
|
97
98
|
Partial<ContactAttribute>,
|
|
98
99
|
'attributeID' | 'contactID' | 'startDate'
|
|
99
100
|
>;
|
|
101
|
+
export type CreateFormResponseParams = WithRequired<
|
|
102
|
+
Omit<Partial<FormResponse>, 'formResponseID'>,
|
|
103
|
+
'formID' | 'responseDate'
|
|
104
|
+
>;
|
|
100
105
|
|
|
101
106
|
export type MPGetOptions = {
|
|
102
107
|
select?: string;
|
|
@@ -200,7 +205,10 @@ export type MPInstance = {
|
|
|
200
205
|
params: CreateContactAttributeParams,
|
|
201
206
|
options?: MPCreateOptions
|
|
202
207
|
): Promise<ContactAttribute | { error: any; }>;
|
|
203
|
-
|
|
208
|
+
createFormResponse(
|
|
209
|
+
params: CreateFormResponseParams,
|
|
210
|
+
options?: MPCreateOptions
|
|
211
|
+
): Promise<FormResponse | { error: any; }>;
|
|
204
212
|
updateContacts(
|
|
205
213
|
contacts: WithRequired<Partial<Contact>, 'contactID'>[],
|
|
206
214
|
options?: MPUpdateOptions
|
|
@@ -300,7 +308,7 @@ export const createMPInstance = ({ auth }: { auth: { username: string; password:
|
|
|
300
308
|
const res = await get<[AddressRecord?]>(
|
|
301
309
|
`/tables/addresses/${id}`, options
|
|
302
310
|
);
|
|
303
|
-
return res.data[0] ?
|
|
311
|
+
return res.data[0] ? convertToCamelCase(res.data[0]) : undefined;
|
|
304
312
|
} catch (err) {
|
|
305
313
|
return { error: err };
|
|
306
314
|
}
|
|
@@ -322,7 +330,7 @@ export const createMPInstance = ({ auth }: { auth: { username: string; password:
|
|
|
322
330
|
const res = await get<[EventRecord?]>(
|
|
323
331
|
`/tables/events/${id}`, options
|
|
324
332
|
);
|
|
325
|
-
return res.data[0] ?
|
|
333
|
+
return res.data[0] ? convertToCamelCase(res.data[0]) : undefined;
|
|
326
334
|
} catch (err) {
|
|
327
335
|
return { error: err };
|
|
328
336
|
}
|
|
@@ -533,6 +541,19 @@ export const createMPInstance = ({ auth }: { auth: { username: string; password:
|
|
|
533
541
|
return { error: err };
|
|
534
542
|
}
|
|
535
543
|
},
|
|
544
|
+
|
|
545
|
+
async createFormResponse(params: CreateFormResponseParams, options = {}) {
|
|
546
|
+
const query = stringifyMPOptions(options);
|
|
547
|
+
try {
|
|
548
|
+
const res = await post<[FormResponseRecord]>(
|
|
549
|
+
`/tables/form_responses${query}`, [
|
|
550
|
+
convertToSnakeCase<CreateFormResponseParams, FormResponseRecord>(params)
|
|
551
|
+
]);
|
|
552
|
+
return convertToCamelCase(res.data[0]);
|
|
553
|
+
} catch (err: any) {
|
|
554
|
+
return { error: err };
|
|
555
|
+
}
|
|
556
|
+
},
|
|
536
557
|
async updateContacts(contacts, options = {}) {
|
|
537
558
|
const query = stringifyMPOptions(options);
|
|
538
559
|
try {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
export interface FormResponseRecord {
|
|
3
|
+
Form_Response_ID: number;
|
|
4
|
+
Form_ID: number;
|
|
5
|
+
Response_Date: string;
|
|
6
|
+
IP_Address: string | null;
|
|
7
|
+
Contact_ID: number;
|
|
8
|
+
First_Name: string;
|
|
9
|
+
Last_Name: string;
|
|
10
|
+
Email_Address: string | null;
|
|
11
|
+
Phone_Number: string | null;
|
|
12
|
+
Address_Line_1: string | null;
|
|
13
|
+
Address_Line_2: string | null;
|
|
14
|
+
Address_City: string | null;
|
|
15
|
+
Address_State: string | null;
|
|
16
|
+
Address_Zip: number |null;
|
|
17
|
+
Event_ID: number;
|
|
18
|
+
Pledge_Campaign_ID: null;
|
|
19
|
+
Opportunity_ID: null;
|
|
20
|
+
Opportunity_Response: null;
|
|
21
|
+
Congregation_ID: number;
|
|
22
|
+
Notification_Sent: boolean;
|
|
23
|
+
Expires: null;
|
|
24
|
+
Event_Participant_ID: number | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export interface FormResponse {
|
|
29
|
+
formResponseID: number;
|
|
30
|
+
formID: number;
|
|
31
|
+
responseDate: string;
|
|
32
|
+
iPAddress: string | null;
|
|
33
|
+
contactID: number;
|
|
34
|
+
firstName: string;
|
|
35
|
+
lastName: string;
|
|
36
|
+
emailAddress: string | null;
|
|
37
|
+
phoneNumber: string | null;
|
|
38
|
+
addressLine1: string | null;
|
|
39
|
+
addressLine2: string | null;
|
|
40
|
+
addressCity: string | null;
|
|
41
|
+
addressState: string | null;
|
|
42
|
+
addressZip: number |null;
|
|
43
|
+
eventID: number;
|
|
44
|
+
pledgeCampaignID: null;
|
|
45
|
+
opportunityID: null;
|
|
46
|
+
opportunityResponse: null;
|
|
47
|
+
congregationID: number;
|
|
48
|
+
notificationSent: boolean;
|
|
49
|
+
expires: null;
|
|
50
|
+
eventParticipantID: number | null;
|
|
51
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export interface FormResponseAnswerRecord {
|
|
4
|
+
Form_Response_Answer_ID: number;
|
|
5
|
+
Form_Field_ID: number;
|
|
6
|
+
Response: string | null;
|
|
7
|
+
Form_Response_ID: number;
|
|
8
|
+
Event_Participant_ID: number | null;
|
|
9
|
+
Pledge_ID: null;
|
|
10
|
+
Opportunity_Response: null;
|
|
11
|
+
Placed: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export interface FormResponseAnswer {
|
|
17
|
+
form_Response_Answer_ID: number;
|
|
18
|
+
form_Field_ID: number;
|
|
19
|
+
response: string | null;
|
|
20
|
+
form_Response_ID: number;
|
|
21
|
+
event_Participant_ID: number | null;
|
|
22
|
+
pledge_ID: null;
|
|
23
|
+
opportunity_Response: null;
|
|
24
|
+
placed: boolean;
|
|
25
|
+
}
|
package/src/utils/strings.ts
CHANGED
|
@@ -25,4 +25,49 @@ export function escapeSql(str: string) {
|
|
|
25
25
|
return char;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export function toCamelCase(str: string) {
|
|
33
|
+
str = str.replace(/((?<=^_|^__))[^\W_]/g, match => match.at(-1)?.toLowerCase() || ''); // keep underscore if first char
|
|
34
|
+
str = str.replace(/(?<!^_|^)_[^\W_]/g, match => match.charAt(1).toUpperCase()); // remove underscore if not first char
|
|
35
|
+
str = str.charAt(0).toLowerCase() + str.slice(1);
|
|
36
|
+
return str.replace(/id$/i, 'ID');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function toCapitalSnakeCase(str: string) {
|
|
40
|
+
str = str.replace(/(?<=^_|^__)[^\W_]/, match => match.at(0)?.toUpperCase() || '');
|
|
41
|
+
str = str.replace(/(?<!_|\/)(ID|[A-Z])/g, match => `_${match}`);
|
|
42
|
+
str = str.charAt(0).toUpperCase() + str.slice(1);
|
|
43
|
+
return str.replace(/_id$/i, '_ID');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Function to recursively convert object keys to Capital_Snake_Case
|
|
47
|
+
export function caseConverter<T>(obj: T, type: 'toCamel' | 'toSnake') {
|
|
48
|
+
const caseFn = type === 'toCamel' ? toCamelCase : toCapitalSnakeCase;
|
|
49
|
+
if (Array.isArray(obj)) {
|
|
50
|
+
return obj.map(val => caseConverter(val, type)); // Recursively process each array element
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (obj !== null && typeof obj === 'object') {
|
|
54
|
+
const snakeCaseObj = {};
|
|
55
|
+
for (const key in obj) {
|
|
56
|
+
if (obj.hasOwnProperty(key)) {
|
|
57
|
+
const snakeCaseKey = caseFn(key); // Convert key to Snake_Case
|
|
58
|
+
snakeCaseObj[snakeCaseKey] = caseConverter(obj[key], type); // Recursively process nested objects
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return snakeCaseObj;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return obj; // Return value if it's neither an array nor an object
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function convertToCamelCase<T = any, R = any>(obj: T): R {
|
|
68
|
+
return caseConverter(obj, 'toCamel');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function convertToSnakeCase<T = any, R = any>(obj: T): R {
|
|
72
|
+
return caseConverter(obj, 'toSnake');
|
|
28
73
|
}
|