feat: update
This commit is contained in:
50
server/api/eoi-send-to-sales.ts
Normal file
50
server/api/eoi-send-to-sales.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await readBody(event);
|
||||
const { interestId } = body;
|
||||
|
||||
if (!interestId) {
|
||||
throw createError({ statusCode: 400, statusMessage: "Interest ID is required" });
|
||||
}
|
||||
|
||||
// Get the interest data
|
||||
const interest = await getInterestById(interestId);
|
||||
|
||||
// Prepare the webhook payload
|
||||
const webhookPayload = {
|
||||
"type": "records.after.trigger",
|
||||
"id": crypto.randomUUID(), // Generate a random UUID
|
||||
"data": {
|
||||
"table_id": "mbs9hjauug4eseo",
|
||||
"table_name": "Interests",
|
||||
"rows": [interest]
|
||||
}
|
||||
};
|
||||
|
||||
// Trigger the webhook
|
||||
const webhookUrl = "https://automation.portnimara.com/api/v1/webhooks/cCRKsqPB9AHuj4XjFFiPr";
|
||||
await triggerWebhook(webhookUrl, webhookPayload);
|
||||
|
||||
// Update the interest to mark that the EOI was sent
|
||||
await updateInterest(interestId, {
|
||||
"EOI Send to Sales": new Date().toISOString()
|
||||
});
|
||||
|
||||
return { success: true, message: "EOI send to sales triggered successfully" };
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw createError({ statusCode: 500, statusMessage: error.message });
|
||||
} else {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "An unexpected error occurred",
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
21
server/api/get-berths.ts
Normal file
21
server/api/get-berths.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
const config = getNocoDbConfiguration();
|
||||
const berthsTableId = "mczgos9hr3oa9qc";
|
||||
|
||||
const berths = await $fetch(`${config.url}/api/v2/tables/${berthsTableId}/records`, {
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
params: {
|
||||
limit: 1000,
|
||||
},
|
||||
});
|
||||
|
||||
return berths;
|
||||
});
|
||||
47
server/api/get-interest-berths.ts
Normal file
47
server/api/get-interest-berths.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
const query = getQuery(event);
|
||||
const { interestId, linkType } = query;
|
||||
|
||||
if (!interestId || !linkType) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "interestId and linkType are required"
|
||||
});
|
||||
}
|
||||
|
||||
const config = getNocoDbConfiguration();
|
||||
const interestsTableId = "mbs9hjauug4eseo";
|
||||
|
||||
// Determine which link field to use
|
||||
let linkFieldId;
|
||||
if (linkType === 'berths') {
|
||||
linkFieldId = "cj7v7bb9pa5eyo3"; // Berths field
|
||||
} else if (linkType === 'recommendations') {
|
||||
linkFieldId = "cgthyq2e95ajc52"; // Berth Recommendations field
|
||||
} else {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "linkType must be 'berths' or 'recommendations'"
|
||||
});
|
||||
}
|
||||
|
||||
const result = await $fetch(
|
||||
`${config.url}/api/v2/tables/${interestsTableId}/links/${linkFieldId}/records/${interestId}`,
|
||||
{
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
params: {
|
||||
limit: 1000,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
});
|
||||
37
server/api/link-berth-recommendations-to-interest.ts
Normal file
37
server/api/link-berth-recommendations-to-interest.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
const body = await readBody(event);
|
||||
const { interestId, berthIds } = body;
|
||||
|
||||
if (!interestId || !berthIds || !Array.isArray(berthIds)) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "interestId and berthIds array are required"
|
||||
});
|
||||
}
|
||||
|
||||
const config = getNocoDbConfiguration();
|
||||
const interestsTableId = "mbs9hjauug4eseo";
|
||||
const berthRecommendationsLinkFieldId = "cgthyq2e95ajc52"; // Berth Recommendations field
|
||||
|
||||
// Format the berth IDs for the API
|
||||
const berthRecords = berthIds.map(id => ({ Id: id }));
|
||||
|
||||
const result = await $fetch(
|
||||
`${config.url}/api/v2/tables/${interestsTableId}/links/${berthRecommendationsLinkFieldId}/records/${interestId}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
body: berthRecords,
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
});
|
||||
37
server/api/link-berths-to-interest.ts
Normal file
37
server/api/link-berths-to-interest.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
const body = await readBody(event);
|
||||
const { interestId, berthIds } = body;
|
||||
|
||||
if (!interestId || !berthIds || !Array.isArray(berthIds)) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "interestId and berthIds array are required"
|
||||
});
|
||||
}
|
||||
|
||||
const config = getNocoDbConfiguration();
|
||||
const interestsTableId = "mbs9hjauug4eseo";
|
||||
const berthsLinkFieldId = "cj7v7bb9pa5eyo3"; // Berths field
|
||||
|
||||
// Format the berth IDs for the API
|
||||
const berthRecords = berthIds.map(id => ({ Id: id }));
|
||||
|
||||
const result = await $fetch(
|
||||
`${config.url}/api/v2/tables/${interestsTableId}/links/${berthsLinkFieldId}/records/${interestId}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
body: berthRecords,
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
});
|
||||
50
server/api/request-more-info-to-sales.ts
Normal file
50
server/api/request-more-info-to-sales.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await readBody(event);
|
||||
const { interestId } = body;
|
||||
|
||||
if (!interestId) {
|
||||
throw createError({ statusCode: 400, statusMessage: "Interest ID is required" });
|
||||
}
|
||||
|
||||
// Get the interest data
|
||||
const interest = await getInterestById(interestId);
|
||||
|
||||
// Prepare the webhook payload
|
||||
const webhookPayload = {
|
||||
"type": "records.after.trigger",
|
||||
"id": crypto.randomUUID(), // Generate a random UUID
|
||||
"data": {
|
||||
"table_id": "mbs9hjauug4eseo",
|
||||
"table_name": "Interests",
|
||||
"rows": [interest]
|
||||
}
|
||||
};
|
||||
|
||||
// Trigger the webhook
|
||||
const webhookUrl = "https://automation.portnimara.com/api/v1/webhooks/vEWQdpe4CXS24E86tV2Cb";
|
||||
await triggerWebhook(webhookUrl, webhookPayload);
|
||||
|
||||
// Update the interest to mark that the request was sent
|
||||
await updateInterest(interestId, {
|
||||
"Request More Info - To Sales": new Date().toISOString()
|
||||
});
|
||||
|
||||
return { success: true, message: "Request more info to sales triggered successfully" };
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw createError({ statusCode: 500, statusMessage: error.message });
|
||||
} else {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "An unexpected error occurred",
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
50
server/api/request-more-information.ts
Normal file
50
server/api/request-more-information.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await readBody(event);
|
||||
const { interestId } = body;
|
||||
|
||||
if (!interestId) {
|
||||
throw createError({ statusCode: 400, statusMessage: "Interest ID is required" });
|
||||
}
|
||||
|
||||
// Get the interest data
|
||||
const interest = await getInterestById(interestId);
|
||||
|
||||
// Prepare the webhook payload
|
||||
const webhookPayload = {
|
||||
"type": "records.after.trigger",
|
||||
"id": crypto.randomUUID(), // Generate a random UUID
|
||||
"data": {
|
||||
"table_id": "mbs9hjauug4eseo",
|
||||
"table_name": "Interests",
|
||||
"rows": [interest]
|
||||
}
|
||||
};
|
||||
|
||||
// Trigger the webhook
|
||||
const webhookUrl = "https://automation.portnimara.com/api/v1/webhooks/B6lnXZoospLXcVJJTABh0";
|
||||
await triggerWebhook(webhookUrl, webhookPayload);
|
||||
|
||||
// Update the interest to mark that the request was sent
|
||||
await updateInterest(interestId, {
|
||||
"Request More Information": new Date().toISOString()
|
||||
});
|
||||
|
||||
return { success: true, message: "Request more information triggered successfully" };
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw createError({ statusCode: 500, statusMessage: error.message });
|
||||
} else {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "An unexpected error occurred",
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
37
server/api/unlink-berth-recommendations-from-interest.ts
Normal file
37
server/api/unlink-berth-recommendations-from-interest.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
const body = await readBody(event);
|
||||
const { interestId, berthIds } = body;
|
||||
|
||||
if (!interestId || !berthIds || !Array.isArray(berthIds)) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "interestId and berthIds array are required"
|
||||
});
|
||||
}
|
||||
|
||||
const config = getNocoDbConfiguration();
|
||||
const interestsTableId = "mbs9hjauug4eseo";
|
||||
const berthRecommendationsLinkFieldId = "cgthyq2e95ajc52"; // Berth Recommendations field
|
||||
|
||||
// Format the berth IDs for the API
|
||||
const berthRecords = berthIds.map(id => ({ Id: id }));
|
||||
|
||||
const result = await $fetch(
|
||||
`${config.url}/api/v2/tables/${interestsTableId}/links/${berthRecommendationsLinkFieldId}/records/${interestId}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
body: berthRecords,
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
});
|
||||
37
server/api/unlink-berths-from-interest.ts
Normal file
37
server/api/unlink-berths-from-interest.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
const body = await readBody(event);
|
||||
const { interestId, berthIds } = body;
|
||||
|
||||
if (!interestId || !berthIds || !Array.isArray(berthIds)) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "interestId and berthIds array are required"
|
||||
});
|
||||
}
|
||||
|
||||
const config = getNocoDbConfiguration();
|
||||
const interestsTableId = "mbs9hjauug4eseo";
|
||||
const berthsLinkFieldId = "cj7v7bb9pa5eyo3"; // Berths field
|
||||
|
||||
// Format the berth IDs for the API
|
||||
const berthRecords = berthIds.map(id => ({ Id: id }));
|
||||
|
||||
const result = await $fetch(
|
||||
`${config.url}/api/v2/tables/${interestsTableId}/links/${berthsLinkFieldId}/records/${interestId}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
body: berthRecords,
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
});
|
||||
38
server/api/update-interest.ts
Normal file
38
server/api/update-interest.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await readBody(event);
|
||||
const { id, data } = body;
|
||||
|
||||
if (!id) {
|
||||
throw createError({ statusCode: 400, statusMessage: "ID is required" });
|
||||
}
|
||||
|
||||
if (!data || Object.keys(data).length === 0) {
|
||||
throw createError({ statusCode: 400, statusMessage: "No data provided for update" });
|
||||
}
|
||||
|
||||
// Remove Id from data if it exists to avoid duplication
|
||||
const updateData = { ...data };
|
||||
if ('Id' in updateData) {
|
||||
delete updateData.Id;
|
||||
}
|
||||
|
||||
const updatedInterest = await updateInterest(id, updateData);
|
||||
return updatedInterest;
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw createError({ statusCode: 500, statusMessage: error.message });
|
||||
} else {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "An unexpected error occurred",
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user