|
| 1 | +import { NextFunction, Request, Response } from 'express'; |
| 2 | +import ProspectiveSponsorServices from '../services/prospective-sponsor.services.js'; |
| 3 | + |
| 4 | +export default class ProspectiveSponsorController { |
| 5 | + static async createProspectiveSponsor(req: Request, res: Response, next: NextFunction) { |
| 6 | + try { |
| 7 | + const { |
| 8 | + organizationName, |
| 9 | + lastContactDate, |
| 10 | + firstContactMethod, |
| 11 | + contactName, |
| 12 | + contactorUserId, |
| 13 | + highlightThresholdDays, |
| 14 | + contactEmail, |
| 15 | + contactPhone, |
| 16 | + contactPosition |
| 17 | + } = req.body; |
| 18 | + |
| 19 | + const prospectiveSponsor = await ProspectiveSponsorServices.createProspectiveSponsor( |
| 20 | + req.currentUser, |
| 21 | + req.organization, |
| 22 | + organizationName, |
| 23 | + lastContactDate, |
| 24 | + firstContactMethod, |
| 25 | + contactName, |
| 26 | + contactorUserId, |
| 27 | + highlightThresholdDays, |
| 28 | + contactEmail, |
| 29 | + contactPhone, |
| 30 | + contactPosition |
| 31 | + ); |
| 32 | + res.status(200).json(prospectiveSponsor); |
| 33 | + } catch (error: unknown) { |
| 34 | + next(error); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + static async getAllProspectiveSponsors(req: Request, res: Response, next: NextFunction) { |
| 39 | + try { |
| 40 | + const prospectiveSponsors = await ProspectiveSponsorServices.getAllProspectiveSponsors(req.organization); |
| 41 | + res.status(200).json(prospectiveSponsors); |
| 42 | + } catch (error: unknown) { |
| 43 | + next(error); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + static async editProspectiveSponsor(req: Request, res: Response, next: NextFunction) { |
| 48 | + try { |
| 49 | + const { prospectiveSponsorId } = req.params as Record<string, string>; |
| 50 | + const { |
| 51 | + organizationName, |
| 52 | + lastContactDate, |
| 53 | + status, |
| 54 | + firstContactMethod, |
| 55 | + contactName, |
| 56 | + contactorUserId, |
| 57 | + highlightThresholdDays, |
| 58 | + contactEmail, |
| 59 | + contactPhone, |
| 60 | + contactPosition |
| 61 | + } = req.body; |
| 62 | + |
| 63 | + const updatedProspectiveSponsor = await ProspectiveSponsorServices.editProspectiveSponsor( |
| 64 | + req.currentUser, |
| 65 | + req.organization, |
| 66 | + prospectiveSponsorId, |
| 67 | + organizationName, |
| 68 | + lastContactDate, |
| 69 | + status, |
| 70 | + firstContactMethod, |
| 71 | + contactName, |
| 72 | + contactorUserId, |
| 73 | + highlightThresholdDays, |
| 74 | + contactEmail, |
| 75 | + contactPhone, |
| 76 | + contactPosition |
| 77 | + ); |
| 78 | + res.status(200).json(updatedProspectiveSponsor); |
| 79 | + } catch (error: unknown) { |
| 80 | + next(error); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + static async deleteProspectiveSponsor(req: Request, res: Response, next: NextFunction) { |
| 85 | + try { |
| 86 | + const { prospectiveSponsorId } = req.params as Record<string, string>; |
| 87 | + const deletedProspectiveSponsor = await ProspectiveSponsorServices.deleteProspectiveSponsor( |
| 88 | + prospectiveSponsorId, |
| 89 | + req.currentUser, |
| 90 | + req.organization |
| 91 | + ); |
| 92 | + res.status(200).json(deletedProspectiveSponsor); |
| 93 | + } catch (error: unknown) { |
| 94 | + next(error); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + static async getProspectiveSponsorTasks(req: Request, res: Response, next: NextFunction) { |
| 99 | + try { |
| 100 | + const { prospectiveSponsorId } = req.params as Record<string, string>; |
| 101 | + const tasks = await ProspectiveSponsorServices.getProspectiveSponsorTasks( |
| 102 | + prospectiveSponsorId, |
| 103 | + req.organization.organizationId |
| 104 | + ); |
| 105 | + res.status(200).json(tasks); |
| 106 | + } catch (error: unknown) { |
| 107 | + next(error); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + static async createProspectiveSponsorTask(req: Request, res: Response, next: NextFunction) { |
| 112 | + try { |
| 113 | + const { prospectiveSponsorId } = req.params as Record<string, string>; |
| 114 | + const { dueDate, notes, notifyDate, assigneeUserId } = req.body; |
| 115 | + |
| 116 | + const task = await ProspectiveSponsorServices.createProspectiveSponsorTask( |
| 117 | + req.currentUser, |
| 118 | + req.organization, |
| 119 | + prospectiveSponsorId, |
| 120 | + dueDate, |
| 121 | + notes, |
| 122 | + notifyDate, |
| 123 | + assigneeUserId |
| 124 | + ); |
| 125 | + res.status(200).json(task); |
| 126 | + } catch (error: unknown) { |
| 127 | + next(error); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + static async acceptProspectiveSponsor(req: Request, res: Response, next: NextFunction) { |
| 132 | + try { |
| 133 | + const { prospectiveSponsorId } = req.params as Record<string, string>; |
| 134 | + const { sponsorTierId, sponsorValue, joinDate, activeYears, taxExempt, discountCode, sponsorNotes } = req.body; |
| 135 | + |
| 136 | + const acceptedProspectiveSponsor = await ProspectiveSponsorServices.acceptProspectiveSponsor( |
| 137 | + req.currentUser, |
| 138 | + req.organization, |
| 139 | + prospectiveSponsorId, |
| 140 | + sponsorTierId, |
| 141 | + sponsorValue, |
| 142 | + joinDate, |
| 143 | + activeYears, |
| 144 | + taxExempt, |
| 145 | + discountCode, |
| 146 | + sponsorNotes |
| 147 | + ); |
| 148 | + res.status(200).json(acceptedProspectiveSponsor); |
| 149 | + } catch (error: unknown) { |
| 150 | + next(error); |
| 151 | + } |
| 152 | + } |
| 153 | +} |
0 commit comments