@@ -36,7 +36,7 @@ import { MembershipRole } from "../interfaces/enum";
3636import { CREATED } from "http-status-codes" ;
3737import asyncHandler from "express-async-handler" ;
3838import { inviteMemberToOrganization } from "../rest/membership" ;
39- import { joiValidate } from "../helpers/utils" ;
39+ import { joiValidate , organizationUsernameToId } from "../helpers/utils" ;
4040import Joi from "@hapi/joi" ;
4141
4242@Controller ( "organizations" )
@@ -71,15 +71,15 @@ export class OrganizationController {
7171
7272 @Get ( ":id" )
7373 async get ( req : Request , res : Response ) {
74- const id = req . params . id ;
74+ const id = await organizationUsernameToId ( req . params . id ) ;
7575 joiValidate ( { id : Joi . number ( ) . required ( ) } , { id } ) ;
7676 const organization = await getOrganizationForUser ( res . locals . token . id , id ) ;
7777 res . json ( organization ) ;
7878 }
7979
8080 @Patch ( ":id" )
8181 async patch ( req : Request , res : Response ) {
82- const id = req . params . id ;
82+ const id = await organizationUsernameToId ( req . params . id ) ;
8383 joiValidate ( { id : Joi . number ( ) . required ( ) } , { id } ) ;
8484 await updateOrganizationForUser (
8585 res . locals . token . id ,
@@ -92,7 +92,7 @@ export class OrganizationController {
9292
9393 @Delete ( ":id" )
9494 async delete ( req : Request , res : Response ) {
95- const organizationId = req . params . id ;
95+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
9696 const userId = res . locals . token . id ;
9797 joiValidate (
9898 { organizationId : Joi . number ( ) . required ( ) } ,
@@ -104,7 +104,7 @@ export class OrganizationController {
104104
105105 @Get ( ":id/billing" )
106106 async getBilling ( req : Request , res : Response ) {
107- const organizationId = req . params . id ;
107+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
108108 joiValidate (
109109 { organizationId : Joi . number ( ) . required ( ) } ,
110110 { organizationId }
@@ -116,7 +116,7 @@ export class OrganizationController {
116116
117117 @Patch ( ":id/billing" )
118118 async patchBilling ( req : Request , res : Response ) {
119- const organizationId = req . params . id ;
119+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
120120 joiValidate (
121121 { organizationId : Joi . number ( ) . required ( ) } ,
122122 { organizationId }
@@ -132,7 +132,7 @@ export class OrganizationController {
132132
133133 @Get ( ":id/invoices" )
134134 async getInvoices ( req : Request , res : Response ) {
135- const organizationId = req . params . id ;
135+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
136136 joiValidate (
137137 { organizationId : Joi . number ( ) . required ( ) } ,
138138 { organizationId }
@@ -159,7 +159,7 @@ export class OrganizationController {
159159
160160 @Get ( ":id/invoices/:invoiceId" )
161161 async getInvoice ( req : Request , res : Response ) {
162- const organizationId = req . params . id ;
162+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
163163 const invoiceId = req . params . invoiceId ;
164164 joiValidate (
165165 {
@@ -179,7 +179,7 @@ export class OrganizationController {
179179
180180 @Get ( ":id/sources" )
181181 async getSources ( req : Request , res : Response ) {
182- const organizationId = req . params . id ;
182+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
183183 joiValidate (
184184 { organizationId : Joi . number ( ) . required ( ) } ,
185185 { organizationId }
@@ -203,7 +203,7 @@ export class OrganizationController {
203203
204204 @Get ( ":id/sources/:sourceId" )
205205 async getSource ( req : Request , res : Response ) {
206- const organizationId = req . params . id ;
206+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
207207 const sourceId = req . params . sourceId ;
208208 joiValidate (
209209 {
@@ -223,7 +223,7 @@ export class OrganizationController {
223223
224224 @Get ( ":id/subscriptions" )
225225 async getSubscriptions ( req : Request , res : Response ) {
226- const organizationId = req . params . id ;
226+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
227227 joiValidate (
228228 { organizationId : Joi . number ( ) . required ( ) } ,
229229 { organizationId }
@@ -250,7 +250,7 @@ export class OrganizationController {
250250
251251 @Get ( ":id/subscriptions/:subscriptionId" )
252252 async getSubscription ( req : Request , res : Response ) {
253- const organizationId = req . params . id ;
253+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
254254 const subscriptionId = req . params . subscriptionId ;
255255 joiValidate (
256256 {
@@ -270,7 +270,7 @@ export class OrganizationController {
270270
271271 @Patch ( ":id/subscriptions/:subscriptionId" )
272272 async patchSubscription ( req : Request , res : Response ) {
273- const organizationId = req . params . id ;
273+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
274274 const subscriptionId = req . params . subscriptionId ;
275275 const data = req . body ;
276276 joiValidate (
@@ -301,7 +301,7 @@ export class OrganizationController {
301301
302302 @Put ( ":id/subscriptions" )
303303 async putSubscriptions ( req : Request , res : Response ) {
304- const organizationId = req . params . id ;
304+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
305305 joiValidate (
306306 { organizationId : Joi . number ( ) . required ( ) } ,
307307 { organizationId }
@@ -328,7 +328,7 @@ export class OrganizationController {
328328 @Get ( ":id/pricing/:product" )
329329 async getPlans ( req : Request , res : Response ) {
330330 const product = req . params . product ;
331- const organizationId = req . params . id ;
331+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
332332 joiValidate (
333333 {
334334 organizationId : Joi . number ( ) . required ( ) ,
@@ -347,7 +347,7 @@ export class OrganizationController {
347347
348348 @Put ( ":id/sources" )
349349 async putSources ( req : Request , res : Response ) {
350- const organizationId = req . params . id ;
350+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
351351 joiValidate (
352352 { organizationId : Joi . number ( ) . required ( ) } ,
353353 { organizationId }
@@ -366,7 +366,7 @@ export class OrganizationController {
366366 @Delete ( ":id/sources/:sourceId" )
367367 async deleteSource ( req : Request , res : Response ) {
368368 const sourceId = req . params . sourceId ;
369- const organizationId = req . params . id ;
369+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
370370 joiValidate (
371371 {
372372 organizationId : Joi . number ( ) . required ( ) ,
@@ -386,7 +386,7 @@ export class OrganizationController {
386386 @Patch ( ":id/sources/:sourceId" )
387387 async patchSource ( req : Request , res : Response ) {
388388 const sourceId = req . params . sourceId ;
389- const organizationId = req . params . id ;
389+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
390390 joiValidate (
391391 {
392392 organizationId : Joi . number ( ) . required ( ) ,
@@ -406,7 +406,7 @@ export class OrganizationController {
406406
407407 @Get ( ":id/data" )
408408 async getData ( req : Request , res : Response ) {
409- const organizationId = req . params . id ;
409+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
410410 joiValidate (
411411 { organizationId : Joi . number ( ) . required ( ) } ,
412412 { organizationId }
@@ -418,7 +418,7 @@ export class OrganizationController {
418418
419419 @Get ( ":id/events" )
420420 async getEvents ( req : Request , res : Response ) {
421- const organizationId = req . params . id ;
421+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
422422 joiValidate (
423423 { organizationId : Joi . number ( ) . required ( ) } ,
424424 { organizationId }
@@ -433,7 +433,7 @@ export class OrganizationController {
433433
434434 @Get ( ":id/memberships" )
435435 async getMemberships ( req : Request , res : Response ) {
436- const organizationId = req . params . id ;
436+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
437437 joiValidate (
438438 { organizationId : Joi . number ( ) . required ( ) } ,
439439 { organizationId }
@@ -449,7 +449,7 @@ export class OrganizationController {
449449
450450 @Put ( ":id/memberships" )
451451 async putMemberships ( req : Request , res : Response ) {
452- const organizationId = req . params . id ;
452+ const organizationId = await organizationUsernameToId ( req . params . id ) ;
453453 const newMemberName = req . body . name ;
454454 const newMemberEmail = req . body . email ;
455455 const role = req . body . role ;
0 commit comments