-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from cellajs/development
refactor: delete self
- Loading branch information
Showing
96 changed files
with
14,333 additions
and
12,096 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { count, eq, sql } from 'drizzle-orm'; | ||
import { db } from '../db/db'; | ||
import { membershipsTable } from '../db/schema/memberships'; | ||
import type { EntityType } from '../types/common'; | ||
|
||
const getQuery = (entity: EntityType) => { | ||
let columnName: keyof typeof membershipsTable; | ||
|
||
switch (entity) { | ||
case 'ORGANIZATION': | ||
columnName = 'organizationId'; | ||
break; | ||
case 'PROJECT': | ||
columnName = 'projectId'; | ||
break; | ||
default: | ||
throw new Error(`Invalid entity type: ${entity}`); | ||
} | ||
|
||
return db | ||
.select({ | ||
id: membershipsTable[columnName], | ||
admins: count(sql`CASE WHEN ${membershipsTable.role} = 'ADMIN' THEN 1 ELSE NULL END`).as('admins'), | ||
members: count().as('members'), | ||
}) | ||
.from(membershipsTable) | ||
.where(eq(membershipsTable.type, entity)) | ||
.groupBy(membershipsTable[columnName]) | ||
.as('counts'); | ||
}; | ||
|
||
export function counts<T extends string | undefined = undefined>( | ||
entity: EntityType, | ||
id?: T, | ||
): T extends string | ||
? Promise<{ memberships: { admins: number; members: number; total: number } }> | ||
: Promise<ReturnType<typeof getQuery>>; | ||
export async function counts(entity: EntityType, id?: string | undefined) { | ||
const query = getQuery(entity); | ||
|
||
if (id) { | ||
const [{ admins, members }] = await db.select().from(query).where(eq(query.id, id)); | ||
return { | ||
memberships: { | ||
admins, | ||
members, | ||
total: members, | ||
}, | ||
}; | ||
} | ||
|
||
return query; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import { config } from 'config'; | ||
import { sendVerificationEmailRouteConfig } from '../routes'; | ||
import authRoutesConfig from '../routes'; | ||
import { logEvent } from '../../../middlewares/logger/log-event'; | ||
|
||
export const sendVerificationEmail = (email: string) => | ||
fetch(config.backendUrl + sendVerificationEmailRouteConfig.path, { | ||
method: sendVerificationEmailRouteConfig.method, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
email, | ||
}), | ||
}); | ||
export const sendVerificationEmail = (email: string) => { | ||
try { | ||
fetch(config.backendAuthUrl + authRoutesConfig.sendVerificationEmail.path, { | ||
method: authRoutesConfig.sendVerificationEmail.method, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
email, | ||
}), | ||
}); | ||
} catch (err) { | ||
return logEvent('Verification email sending failed'); | ||
} | ||
}; |
Oops, something went wrong.