Deploy to production - ensure all endpoints operational
This commit is contained in:
2
api/deploy-package/donations/createDonation.d.ts
vendored
Normal file
2
api/deploy-package/donations/createDonation.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';
|
||||
export declare function createDonation(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit>;
|
||||
128
api/deploy-package/donations/createDonation.js
Normal file
128
api/deploy-package/donations/createDonation.js
Normal file
@@ -0,0 +1,128 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createDonation = createDonation;
|
||||
const functions_1 = require("@azure/functions");
|
||||
const DIContainer_1 = __importDefault(require("../DIContainer"));
|
||||
const uuid_1 = require("uuid");
|
||||
const stripe_1 = __importDefault(require("stripe"));
|
||||
async function createDonation(request, context) {
|
||||
try {
|
||||
await DIContainer_1.default.getInstance().initializeServices();
|
||||
const { donationsContainer, secretClient } = DIContainer_1.default.getInstance().getServices();
|
||||
// Get request body
|
||||
const donationRequest = await request.json();
|
||||
// Validate required fields
|
||||
if (!donationRequest.amount || !donationRequest.donorEmail || !donationRequest.donorName) {
|
||||
const response = {
|
||||
success: false,
|
||||
error: 'Missing required fields: amount, donorEmail, donorName',
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
return {
|
||||
status: 400,
|
||||
jsonBody: response,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
};
|
||||
}
|
||||
// Initialize Stripe if payment method is stripe
|
||||
let stripePaymentIntentId;
|
||||
if (donationRequest.paymentMethod === 'stripe') {
|
||||
try {
|
||||
const stripeSecretKey = await secretClient.getSecret('stripe-secret-key');
|
||||
const stripe = new stripe_1.default(stripeSecretKey.value, {
|
||||
apiVersion: '2025-02-24.acacia'
|
||||
});
|
||||
const paymentIntent = await stripe.paymentIntents.create({
|
||||
amount: Math.round(donationRequest.amount * 100), // Convert to cents
|
||||
currency: donationRequest.currency.toLowerCase(),
|
||||
metadata: {
|
||||
donorEmail: donationRequest.donorEmail,
|
||||
donorName: donationRequest.donorName,
|
||||
program: donationRequest.program || 'general'
|
||||
}
|
||||
});
|
||||
stripePaymentIntentId = paymentIntent.id;
|
||||
}
|
||||
catch (stripeError) {
|
||||
context.error('Stripe payment intent creation failed:', stripeError);
|
||||
const response = {
|
||||
success: false,
|
||||
error: 'Payment processing failed',
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
return {
|
||||
status: 500,
|
||||
jsonBody: response,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
// Create donation record
|
||||
const donation = {
|
||||
id: (0, uuid_1.v4)(),
|
||||
amount: donationRequest.amount,
|
||||
currency: donationRequest.currency,
|
||||
donorName: donationRequest.donorName,
|
||||
donorEmail: donationRequest.donorEmail,
|
||||
donorPhone: donationRequest.donorPhone,
|
||||
program: donationRequest.program,
|
||||
isRecurring: donationRequest.isRecurring,
|
||||
frequency: donationRequest.frequency,
|
||||
paymentMethod: donationRequest.paymentMethod,
|
||||
stripePaymentIntentId,
|
||||
status: 'pending',
|
||||
message: donationRequest.message,
|
||||
isAnonymous: donationRequest.isAnonymous,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString()
|
||||
};
|
||||
// Save to Cosmos DB
|
||||
await donationsContainer.items.create(donation);
|
||||
const response = {
|
||||
success: true,
|
||||
data: donation,
|
||||
message: 'Donation created successfully',
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
return {
|
||||
status: 201,
|
||||
jsonBody: response,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
context.error('Error creating donation:', error);
|
||||
const response = {
|
||||
success: false,
|
||||
error: 'Failed to create donation',
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
return {
|
||||
status: 500,
|
||||
jsonBody: response,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
functions_1.app.http('createDonation', {
|
||||
methods: ['POST'],
|
||||
authLevel: 'anonymous',
|
||||
route: 'donations',
|
||||
handler: createDonation
|
||||
});
|
||||
//# sourceMappingURL=createDonation.js.map
|
||||
1
api/deploy-package/donations/createDonation.js.map
Normal file
1
api/deploy-package/donations/createDonation.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"createDonation.js","sourceRoot":"","sources":["../../src/donations/createDonation.ts"],"names":[],"mappings":";;;;;AAMA,wCAyHC;AA/HD,gDAAyF;AACzF,iEAAyC;AAEzC,+BAAoC;AACpC,oDAA4B;AAErB,KAAK,UAAU,cAAc,CAAC,OAAoB,EAAE,OAA0B;IACnF,IAAI,CAAC;QACH,MAAM,qBAAW,CAAC,WAAW,EAAE,CAAC,kBAAkB,EAAE,CAAC;QACrD,MAAM,EAAE,kBAAkB,EAAE,YAAY,EAAE,GAAG,qBAAW,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,CAAC;QAErF,mBAAmB;QACnB,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,IAAI,EAA2B,CAAC;QAEtE,2BAA2B;QAC3B,IAAI,CAAC,eAAe,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,UAAU,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;YACzF,MAAM,QAAQ,GAAgB;gBAC5B,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,wDAAwD;gBAC/D,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC,CAAC;YAEF,OAAO;gBACL,MAAM,EAAE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M,QAAQ,GAAgB;YAC5B,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,2BAA2B;YAClC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,GAAG;YACX,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,6BAA6B,EAAE,GAAG;aACnC;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,eAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE;IACzB,OAAO,EAAE,CAAC,MAAM,CAAC;IACjB,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,WAAW;IAClB,OAAO,EAAE,cAAc;CACxB,CAAC,CAAC"}
|
||||
2
api/deploy-package/donations/getDonations.d.ts
vendored
Normal file
2
api/deploy-package/donations/getDonations.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';
|
||||
export declare function getDonations(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit>;
|
||||
83
api/deploy-package/donations/getDonations.js
Normal file
83
api/deploy-package/donations/getDonations.js
Normal file
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getDonations = getDonations;
|
||||
const functions_1 = require("@azure/functions");
|
||||
const DIContainer_1 = __importDefault(require("../DIContainer"));
|
||||
async function getDonations(request, context) {
|
||||
try {
|
||||
await DIContainer_1.default.getInstance().initializeServices();
|
||||
const { donationsContainer } = DIContainer_1.default.getInstance().getServices();
|
||||
const page = parseInt(request.query.get('page') || '1');
|
||||
const limit = parseInt(request.query.get('limit') || '10');
|
||||
const status = request.query.get('status');
|
||||
const program = request.query.get('program');
|
||||
let query = 'SELECT * FROM c WHERE 1=1';
|
||||
const parameters = [];
|
||||
if (status) {
|
||||
query += ' AND c.status = @status';
|
||||
parameters.push({ name: '@status', value: status });
|
||||
}
|
||||
if (program) {
|
||||
query += ' AND c.program = @program';
|
||||
parameters.push({ name: '@program', value: program });
|
||||
}
|
||||
query += ' ORDER BY c.createdAt DESC';
|
||||
const { resources: donations } = await donationsContainer.items
|
||||
.query({
|
||||
query,
|
||||
parameters
|
||||
})
|
||||
.fetchAll();
|
||||
// Simple pagination
|
||||
const total = donations.length;
|
||||
const pages = Math.ceil(total / limit);
|
||||
const startIndex = (page - 1) * limit;
|
||||
const endIndex = startIndex + limit;
|
||||
const paginatedDonations = donations.slice(startIndex, endIndex);
|
||||
const response = {
|
||||
success: true,
|
||||
data: paginatedDonations,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
pages
|
||||
},
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
return {
|
||||
status: 200,
|
||||
jsonBody: response,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
context.error('Error fetching donations:', error);
|
||||
const response = {
|
||||
success: false,
|
||||
error: 'Failed to fetch donations',
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
return {
|
||||
status: 500,
|
||||
jsonBody: response,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
functions_1.app.http('getDonations', {
|
||||
methods: ['GET'],
|
||||
authLevel: 'anonymous',
|
||||
route: 'donations',
|
||||
handler: getDonations
|
||||
});
|
||||
//# sourceMappingURL=getDonations.js.map
|
||||
1
api/deploy-package/donations/getDonations.js.map
Normal file
1
api/deploy-package/donations/getDonations.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getDonations.js","sourceRoot":"","sources":["../../src/donations/getDonations.ts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