Skip to content

Commit 4107a78

Browse files
committed
Better handling of engagements, but we have to modify the DB to have locks / consumed values tied now to either challenges or engagements.
1 parent b63de0a commit 4107a78

19 files changed

Lines changed: 1474 additions & 184 deletions

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ DATABASE_URL="postgresql://postgres:postgres@localhost:5432/topcoder-services?sc
44
# Example: postgresql://postgres:postgres@localhost:5432/topcoder-services?schema=members
55
MEMBER_DB_URL=""
66

7+
# Optional lookup stores used to resolve billing-account line-item names.
8+
# If unset, line items are still returned with externalName omitted.
9+
CHALLENGE_DB_URL="postgresql://postgres:postgres@localhost:5432/topcoder-services?schema=challenges"
10+
ENGAGEMENTS_DB_URL="postgresql://postgres:postgres@localhost:5432/engagements"
11+
712
# Auth (tc-core-library-js)
813
AUTH_SECRET=""
914
AUTH0_URL="" # e.g. https://topcoder-dev.auth0.com/ (optional)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
- Endpoints:
88
- `GET /billing-accounts`
99
- `POST /billing-accounts`
10-
- `GET /billing-accounts/:billingAccountId` (includes locked/consumed arrays + budget totals)
10+
- `GET /billing-accounts/:billingAccountId` (includes locked/consumed arrays + budget totals; line items expose `amount`, `date`, `externalId`, `externalType`, `externalName`, and `challengeId` only for challenge compatibility)
1111
- `GET /billing-accounts/users/:userId` (list billing accounts accessible by the given Topcoder user ID — resolved via Salesforce resource object)
1212
- `PATCH /billing-accounts/:billingAccountId`
13-
- `PATCH /billing-accounts/:billingAccountId/lock-amount` (0 amount = unlock)
14-
- `PATCH /billing-accounts/:billingAccountId/consume-amount` (deletes locks for challenge, then upserts consumed)
13+
- `PATCH /billing-accounts/:billingAccountId/lock-amount` (challenge-only typed reference; non-negative amount; 0 amount = unlock; rejects insufficient remaining funds)
14+
- `PATCH /billing-accounts/:billingAccountId/consume-amount` (positive amount; challenge typed references delete the matching lock and overwrite consumed; engagement typed references append a consumed row; rejects insufficient remaining funds)
1515
- `GET /billing-accounts/:billingAccountId/users` (list users with access)
1616
- `POST /billing-accounts/:billingAccountId/users` (grant access; accepts `{ param: { userId } }` or `{ userId }`)
1717
- `DELETE /billing-accounts/:billingAccountId/users/:userId` (revoke access)

packages/ba-prisma-client/edge.js

Lines changed: 15 additions & 9 deletions
Large diffs are not rendered by default.

packages/ba-prisma-client/index-browser.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ exports.Prisma.BillingAccountScalarFieldEnum = {
158158
exports.Prisma.LockedAmountScalarFieldEnum = {
159159
id: 'id',
160160
billingAccountId: 'billingAccountId',
161-
challengeId: 'challengeId',
161+
externalId: 'externalId',
162+
externalType: 'externalType',
162163
amount: 'amount',
163164
createdAt: 'createdAt',
164165
updatedAt: 'updatedAt'
@@ -167,7 +168,8 @@ exports.Prisma.LockedAmountScalarFieldEnum = {
167168
exports.Prisma.ConsumedAmountScalarFieldEnum = {
168169
id: 'id',
169170
billingAccountId: 'billingAccountId',
170-
challengeId: 'challengeId',
171+
externalId: 'externalId',
172+
externalType: 'externalType',
171173
amount: 'amount',
172174
createdAt: 'createdAt',
173175
updatedAt: 'updatedAt'
@@ -204,6 +206,11 @@ exports.BAStatus = exports.$Enums.BAStatus = {
204206
INACTIVE: 'INACTIVE'
205207
};
206208

209+
exports.BudgetEntryExternalType = exports.$Enums.BudgetEntryExternalType = {
210+
CHALLENGE: 'CHALLENGE',
211+
ENGAGEMENT: 'ENGAGEMENT'
212+
};
213+
207214
exports.Prisma.ModelName = {
208215
Client: 'Client',
209216
BillingAccount: 'BillingAccount',

0 commit comments

Comments
 (0)