Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Remove duplicate typeorm helpers

Blue Mouse1062b4997d08
diff --git a/backend/apps/production/src/alert/alert.controller.ts b/backend/apps/production/src/alert/alert.controller.ts
index 863360ad7..4316c7943 100644
--- a/backend/apps/production/src/alert/alert.controller.ts
+++ b/backend/apps/production/src/alert/alert.controller.ts
@@ -57,7 +57,11 @@ export class AlertController {
) {
this.logger.log({ userId, take, skip }, 'GET /alert')
- const projects = await this.projectService.findWhere({ admin: userId })
+ const projects = await this.projectService.find({
+ where: {
+ admin: { id: userId },
+ },
+ })
if (_isEmpty(projects)) {
return []
diff --git a/backend/apps/production/src/alert/alert.service.ts b/backend/apps/production/src/alert/alert.service.ts
index 12d6e2837..c8a0a7b21 100644
--- a/backend/apps/production/src/alert/alert.service.ts
+++ b/backend/apps/production/src/alert/alert.service.ts
@@ -14,7 +14,7 @@ export class AlertService {
async paginate(
options: PaginationOptionsInterface,
- where: Record<string, unknown> | undefined,
+ where: FindManyOptions<Alert>['where'],
relations?: Array<string>,
): Promise<Pagination<Alert>> {
const [results, total] = await this.alertsReporsitory.findAndCount({
@@ -48,13 +48,6 @@ export class AlertService {
return this.alertsReporsitory.findOne(options)
}
- findWhere(
- where: Record<string, unknown>,
- relations?: string[],
- ): Promise<Alert[]> {
- return this.alertsReporsitory.find({ where, relations })
- }
-
find(options: FindManyOptions<Alert>): Promise<Alert[]> {
return this.alertsReporsitory.find(options)
}
diff --git a/backend/apps/production/src/auth/auth.service.ts b/backend/apps/production/src/auth/auth.service.ts
index 1385c7f60..4dafeccbd 100644
--- a/backend/apps/production/src/auth/auth.service.ts
+++ b/backend/apps/production/src/auth/auth.service.ts
@@ -519,8 +519,8 @@ export class AuthService {
referrerId,
}
- const userWithSameEmail = await this.userService.findOneWhere({
- email,
+ const userWithSameEmail = await this.userService.findOne({
+ where: { email },
})
if (userWithSameEmail) {
@@ -591,8 +591,8 @@ export class AuthService {
let referrerID
if (refCode) {
- const referrer = await this.userService.findOneWhere({
- refCode,
+ const referrer = await this.userService.findOne({
+ where: { refCode },
})
if (referrer) {
@@ -636,8 +636,8 @@ export class AuthService {
const { sub, email } = await this.processHash(ssoHash)
try {
- const user = await this.userService.findOneWhere({
- googleId: sub,
+ const user = await this.userService.findOne({
+ where: { googleId: sub },
})
if (!user) {
@@ -742,8 +742,8 @@ export class AuthService {
)
}
- const subUser = await this.userService.findOneWhere({
- googleId: sub,
+ const subUser = await this.userService.findOne({
+ where: { googleId: sub },
})
if (subUser) {
@@ -909,8 +909,8 @@ export class AuthService {
referrerId,
}
- const userWithSameEmail = await this.userService.findOneWhere({
- email,
+ const userWithSameEmail = await this.userService.findOne({
+ where: { email },
})
if (userWithSameEmail) {
@@ -984,8 +984,8 @@ export class AuthService {
)
}
- const subUser = await this.userService.findOneWhere({
- githubId: id,
+ const subUser = await this.userService.findOne({
+ where: { githubId: id },
})
if (subUser) {
@@ -1014,8 +1014,8 @@ export class AuthService {
const { id, email } = await this.processHash(ssoHash)
try {
- const user = await this.userService.findOneWhere({
- githubId: id,
+ const user = await this.userService.findOne({
+ where: { githubId: id },
})
if (!user) {
diff --git a/backend/apps/production/src/marketplace/categories/categories.service.ts b/backend/apps/production/src/marketplace/categories/categories.service.ts
index ca2ed410b..3fa714e5f 100644
--- a/backend/apps/production/src/marketplace/categories/categories.service.ts
+++ b/backend/apps/production/src/marketplace/categories/categories.service.ts
@@ -40,7 +40,7 @@ export class CategoriesService {
async findAndCount(
options: FindManyOptions<Category>,
): Promise<[Category[], number]> {
- return this.categoryRepository.findAndCount({ ...options })
+ return this.categoryRepository.findAndCount(options)
}
async findByName(name: string): Promise<Category> {
diff --git a/backend/apps/production/src/payouts/payouts.service.ts b/backend/apps/production/src/payouts/payouts.service.ts
index 8f42e3c08..4b33229bd 100644
--- a/backend/apps/production/src/payouts/payouts.service.ts
+++ b/backend/apps/production/src/payouts/payouts.service.ts
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
-import { Repository } from 'typeorm'
+import { FindManyOptions, Repository } from 'typeorm'
import { Payout, PayoutStatus } from './entities/payouts.entity'
import { Pagination, PaginationOptionsInterface } from '../common/pagination'
@@ -52,7 +52,7 @@ export class PayoutsService {
async paginate(
options: PaginationOptionsInterface,
- where: Record<string, unknown> | undefined,
+ where: FindManyOptions<Payout>['where'],
): Promise<Pagination<Payout>> {
const [results, total] = await this.payoutsRepository.findAndCount({
take: options.take || 100,
diff --git a/backend/apps/production/src/project/project.controller.ts b/backend/apps/production/src/project/project.controller.ts
index de6486434..c1a426768 100644
--- a/backend/apps/production/src/project/project.controller.ts
+++ b/backend/apps/production/src/project/project.controller.ts
@@ -163,7 +163,9 @@ export class ProjectController {
if (search) {
where = [
{
- admin: userId,
+ admin: {
+ id: userId,
+ },
isCaptchaProject: isCaptcha,
isAnalyticsProject: !isCaptcha,
name: ILike(`%${search}%`),
@@ -171,7 +173,9 @@ export class ProjectController {
// name: ILike(`%${mysql.escape(search).slice(1, 0).slice(0, -1)}%`),
},
{
- admin: userId,
+ admin: {
+ id: userId,
+ },
isCaptchaProject: isCaptcha,
isAnalyticsProject: !isCaptcha,
id: ILike(`%${search}%`),
@@ -181,7 +185,9 @@ export class ProjectController {
] as FindOptionsWhere<Project>[]
} else {
where = {
- admin: userId,
+ admin: {
+ id: userId,
+ },
} as FindOptionsWhere<Project>
if (isCaptcha) {
@@ -259,25 +265,29 @@ export class ProjectController {
): Promise<Pagination<ProjectShare> | ProjectShare[] | object> {
this.logger.log({ userId, take, skip, search }, 'GET /project/shared')
- let where = Object()
+ let where: FindOptionsWhere<ProjectShare> | FindOptionsWhere<ProjectShare>[]
if (search) {
where = [
{
- user: userId,
+ user: { id: userId },
project: {
name: ILike(`%${search}%`),
},
},
{
- user: userId,
+ user: { id: userId },
project: {
id: ILike(`%${search}%`),
},
},
- ]
+ ] as FindOptionsWhere<ProjectShare>[]
} else {
- where.user = userId
+ where = {
+ user: {
+ id: userId,
+ },
+ } as FindOptionsWhere<ProjectShare>
}
const paginated = await this.projectService.paginateShared(
@@ -327,8 +337,7 @@ export class ProjectController {
): Promise<Project | object> {
this.logger.log({ take, skip }, 'GET /all')
- const where = Object()
- return this.projectService.paginate({ take, skip }, where)
+ return this.projectService.paginate({ take, skip })
}
@ApiBearerAuth()
@@ -1038,12 +1047,10 @@ export class ProjectController {
await Promise.all(
bulkAddUsersDto.users.map(async invitationObject => {
- const invitee = await this.userService.findOneWhere(
- {
- email: invitationObject.email,
- },
- ['sharedProjects'],
- )
+ const invitee = await this.userService.findOne({
+ where: { email: invitationObject.email },
+ relations: ['sharedProjects'],
+ })
if (!invitee) {
this.logger.warn(
@@ -1211,12 +1218,10 @@ export class ProjectController {
this.projectService.allowedToManage(project, uid, user.roles)
- const invitee = await this.userService.findOneWhere(
- {
- email: shareDTO.email,
- },
- ['sharedProjects'],
- )
+ const invitee = await this.userService.findOne({
+ where: { email: shareDTO.email },
+ relations: ['sharedProjects'],
+ })
if (!invitee) {
throw new NotFoundException(
@@ -1400,7 +1405,9 @@ export class ProjectController {
throw new NotFoundException('Project not found.')
}
- const user = await this.userService.getUserByEmail(body.email)
+ const user = await this.userService.findOne({
+ where: { email: body.email },
+ })
if (!user) {
throw new NotFoundException('User not found.')
@@ -1549,7 +1556,7 @@ export class ProjectController {
"You are not allowed to manage this project's subscribers",
)
- const user = await this.userService.getUser(userId)
+ const user = await this.userService.findOne({ where: { id: userId } })
if (user.email === body.email) {
throw new BadRequestException('You cannot subscribe to your own project.')
@@ -2070,7 +2077,11 @@ export class ProjectController {
): Promise<Pagination<MonitorEntity>> {
this.logger.log({ userId, take, skip }, 'GET /project/monitors')
- const projects = await this.projectService.findWhere({ admin: userId })
+ const projects = await this.projectService.find({
+ where: {
+ admin: { id: userId },
+ },
+ })
if (_isEmpty(projects)) {
return {
diff --git a/backend/apps/production/src/project/project.service.ts b/backend/apps/production/src/project/project.service.ts
index 236508709..920689f34 100644
--- a/backend/apps/production/src/project/project.service.ts
+++ b/backend/apps/production/src/project/project.service.ts
@@ -374,7 +374,7 @@ export class ProjectService {
async paginate(
options: PaginationOptionsInterface,
- where: FindOptionsWhere<Project> | FindOptionsWhere<Project>[] | undefined,
+ where?: FindOptionsWhere<Project> | FindOptionsWhere<Project>[],
): Promise<Pagination<Project>> {
const [results, total] = await this.projectsRepository.findAndCount({
take: options.take || 100,
@@ -394,7 +394,7 @@ export class ProjectService {
async paginateShared(
options: PaginationOptionsInterface,
- where: FindOptionsWhere<Project> | FindOptionsWhere<Project>[] | undefined,
+ where: FindOptionsWhere<ProjectShare> | FindOptionsWhere<ProjectShare>[],
): Promise<Pagination<ProjectShare>> {
const [results, total] = await this.projectShareRepository.findAndCount({
take: options.take || 100,
@@ -482,13 +482,6 @@ export class ProjectService {
return this.projectsRepository.findOne(options)
}
- findWhere(
- where: Record<string, unknown> | Record<string, unknown>[],
- relations?: string[],
- ) {
- return this.projectsRepository.find({ where, relations })
- }
-
find(options: FindManyOptions<Project>) {
return this.projectsRepository.find(options)
}
@@ -892,8 +885,10 @@ export class ProjectService {
}
async clearProjectsRedisCache(uid: string): Promise<void> {
- const projects = await this.findWhere({
- admin: uid,
+ const projects = await this.find({
+ where: {
+ admin: { id: uid },
+ },
})
if (_isEmpty(projects)) {
@@ -906,7 +901,7 @@ export class ProjectService {
}
async clearProjectsRedisCacheByEmail(email: string): Promise<void> {
- const user = await this.userService.findOneWhere({ email })
+ const user = await this.userService.findOne({ where: { email } })
if (!user) {
return
@@ -916,7 +911,7 @@ export class ProjectService {
}
async clearProjectsRedisCacheBySubId(subID: string): Promise<void> {
- const user = await this.userService.findOneWhere({ subID })
+ const user = await this.userService.findOne({ where: { subID } })
if (!user) {
return
@@ -1085,7 +1080,7 @@ export class ProjectService {
})
}
- async findOneSubscriber(where: Record<string, unknown>) {
+ async findOneSubscriber(where: FindOneOptions<ProjectSubscriber>['where']) {
return this.projectSubscriberRepository.findOne({ where })
}
@@ -1500,7 +1495,7 @@ export class ProjectService {
async paginateMonitors(
options: PaginationOptionsInterface,
- where: Record<string, unknown> | undefined,
+ where: FindManyOptions<MonitorEntity>['where'],
): Promise<Pagination<MonitorEntity>> {
const [results, total] = await this.monitorRepository.findAndCount({
take: options.take || 100,
diff --git a/backend/apps/production/src/task-manager/task-manager.service.ts b/backend/apps/production/src/task-manager/task-manager.service.ts
index 892183dc7..3b8807004 100644
--- a/backend/apps/production/src/task-manager/task-manager.service.ts
+++ b/backend/apps/production/src/task-manager/task-manager.service.ts
@@ -928,8 +928,8 @@ export class TaskManagerService {
@Cron(CronExpression.EVERY_5_MINUTES)
async checkOnlineUsersAlerts() {
- const projects = await this.projectService.findWhere(
- [
+ const projects = await this.projectService.find({
+ where: [
{
admin: {
isTelegramChatIdConfirmed: true,
@@ -952,17 +952,17 @@ export class TaskManagerService {
},
},
],
- ['admin'],
- )
+ relations: ['admin'],
+ })
- const alerts = await this.alertService.findWhere(
- {
+ const alerts = await this.alertService.find({
+ where: {
project: In(_map(projects, 'id')),
active: true,
queryMetric: QueryMetric.ONLINE_USERS,
},
- ['project'],
- )
+ relations: ['project'],
+ })
const promises = _map(alerts, async alert => {
const project = _find(projects, { id: alert.project.id })
@@ -1014,24 +1014,24 @@ export class TaskManagerService {
@Cron(CronExpression.EVERY_5_MINUTES)
async checkMetricAlerts() {
- const projects = await this.projectService.findWhere(
- {
+ const projects = await this.projectService.find({
+ where: {
admin: {
planCode: Not(PlanCode.none),
dashboardBlockReason: IsNull(),
},
},
- ['admin'],
- )
+ relations: ['admin'],
+ })
- const alerts = await this.alertService.findWhere(
- {
+ const alerts = await this.alertService.find({
+ where: {
project: In(_map(projects, 'id')),
active: true,
queryMetric: Not(QueryMetric.ONLINE_USERS),
},
- ['project'],
- )
+ relations: ['project'],
+ })
const promises = _map(alerts, async alert => {
const project = _find(projects, { id: alert.project.id })
diff --git a/backend/apps/production/src/twoFactorAuth/twoFactorAuth.controller.ts b/backend/apps/production/src/twoFactorAuth/twoFactorAuth.controller.ts
index c8847f14f..a50f38475 100644
--- a/backend/apps/production/src/twoFactorAuth/twoFactorAuth.controller.ts
+++ b/backend/apps/production/src/twoFactorAuth/twoFactorAuth.controller.ts
@@ -44,7 +44,7 @@ export class TwoFactorAuthController {
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@TwoFaNotRequired()
async register(@CurrentUserId() id: string) {
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
return this.twoFactorAuthService.generateTwoFactorAuthenticationSecret(user)
}
@@ -65,7 +65,7 @@ export class TwoFactorAuthController {
const ip = getIPFromHeaders(headers) || reqIP || ''
await checkRateLimit(ip, '2fa-enable', 10, 1800)
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
const { twoFactorAuthenticationCode } = body
const isCodeValid =
@@ -113,7 +113,7 @@ export class TwoFactorAuthController {
const ip = getIPFromHeaders(headers) || reqIP || ''
await checkRateLimit(ip, '2fa-disable', 10, 1800)
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
const { twoFactorAuthenticationCode } = body
const isCodeValid =
@@ -153,7 +153,7 @@ export class TwoFactorAuthController {
const ip = getIPFromHeaders(headers) || reqIP || ''
await checkRateLimit(ip, '2fa-auth', 10, 1800)
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
const { twoFactorAuthenticationCode } = body
const isCodeValid =
diff --git a/backend/apps/production/src/user/user.controller.ts b/backend/apps/production/src/user/user.controller.ts
index fb9504184..7d825d965 100644
--- a/backend/apps/production/src/user/user.controller.ts
+++ b/backend/apps/production/src/user/user.controller.ts
@@ -500,7 +500,7 @@ export class UserController {
): Promise<boolean> {
this.logger.log({ id }, 'POST /user/confirm_email')
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
if (
!user ||
@@ -541,7 +541,7 @@ export class UserController {
userDTO.password = await this.authService.hashPassword(userDTO.password)
}
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
try {
if (!user) {
@@ -573,7 +573,7 @@ export class UserController {
): Promise<any> {
this.logger.log({ tgID, id }, 'DELETE /user/tg/:id')
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
if (tgID && user.telegramChatId === tgID) {
await this.userService.update(id, {
@@ -593,7 +593,7 @@ export class UserController {
@Req() request: Request,
): Promise<Partial<User>> {
this.logger.log({ userDTO, id }, 'PUT /user')
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
const shouldUpdatePassword =
!_isEmpty(userDTO.password) && _isString(userDTO.password)
@@ -608,8 +608,8 @@ export class UserController {
try {
if (userDTO.email && user.email !== userDTO.email) {
- const userWithByEmail = await this.userService.findOneWhere({
- email: userDTO.email,
+ const userWithByEmail = await this.userService.findOne({
+ where: { email: userDTO.email },
})
if (userWithByEmail) {
@@ -638,8 +638,8 @@ export class UserController {
userDTO.telegramChatId &&
user.telegramChatId !== userDTO.telegramChatId
) {
- const userWithByTelegramChatId = await this.userService.findOneWhere({
- telegramChatId: userDTO.telegramChatId,
+ const userWithByTelegramChatId = await this.userService.findOne({
+ where: { telegramChatId: userDTO.telegramChatId },
})
if (userWithByTelegramChatId) {
@@ -749,7 +749,7 @@ export class UserController {
await this.authService.logoutAll(id)
}
- const updatedUser = await this.userService.findOneWhere({ id })
+ const updatedUser = await this.userService.findOne({ where: { id } })
return this.userService.omitSensitiveData(updatedUser)
} catch (reason) {
throw new BadRequestException(reason.message)
@@ -769,7 +769,7 @@ export class UserController {
// ): Promise<Pagination<Payout> | Payout[]> {
// this.logger.log({ id, take, skip }, 'GET /user/payouts/list')
- // const user = await this.userService.findOneWhere({ id })
+ // const user = await this.userService.findOne({ where: { id } })
// if (!user) {
// throw new BadRequestException('User not found')
@@ -785,7 +785,7 @@ export class UserController {
async getReferralsList(@CurrentUserId() id: string): Promise<any> {
this.logger.log({ id }, 'GET /user/referrals')
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
if (!user) {
throw new BadRequestException('User not found')
@@ -801,7 +801,7 @@ export class UserController {
async getPayoutsInfo(@CurrentUserId() id: string): Promise<any> {
this.logger.log({ id }, 'GET /user/payouts/info')
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
if (!user) {
throw new BadRequestException('User not found')
@@ -817,7 +817,7 @@ export class UserController {
async generateRefCode(@CurrentUserId() id: string): Promise<any> {
this.logger.log({ id }, 'POST /user/generate-ref-code')
- const user = await this.userService.findOneWhere({ id })
+ const user = await this.userService.findOne({ where: { id } })
if (!user) {
throw new BadRequestException('User not found')
@@ -847,9 +847,13 @@ export class UserController {
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async exportUserData(@CurrentUserId() user_id: string): Promise<User> {
this.logger.log({ user_id }, 'GET /user/export')
- const user = await this.userService.findOneWhere({ id: user_id })
- const where = Object({ admin: user_id })
- const projects = await this.projectService.findWhere(where, ['alerts'])
+ const user = await this.userService.findOne({ where: { id: user_id } })
+ const projects = await this.projectService.find({
+ where: {
+ admin: { id: user_id },
+ },
+ relations: ['alerts'],
+ })
if (
!_isNull(user.exportedAt) &&
@@ -989,9 +993,7 @@ export class UserController {
throw new NotFoundException('Unsubscribe token is invalid')
}
- const user = await this.userService.findOneWhere({
- id: userId,
- })
+ const user = await this.userService.findOne({ where: { id: userId } })
if (!user) {
throw new NotFoundException('Unsubscribe token is invalid')
diff --git a/backend/apps/production/src/user/user.service.ts b/backend/apps/production/src/user/user.service.ts
index b376c2cec..e310eea32 100644
--- a/backend/apps/production/src/user/user.service.ts
+++ b/backend/apps/production/src/user/user.service.ts
@@ -172,36 +172,14 @@ export class UserService {
])
}
- findOneWhere(
- where: Record<string, unknown>,
- relations?: string[],
- select?: any,
- ): Promise<User> {
- return this.usersRepository.findOne({ where, relations, select })
- }
-
findOne(options: FindOneOptions<User> = {}): Promise<User> {
return this.usersRepository.findOne(options)
}
- findWhereWithRelations(
- where: Record<string, unknown>,
- relations: string[],
- ): Promise<User[]> {
- return this.usersRepository.find({
- where,
- relations,
- })
- }
-
find(options: FindManyOptions<User>): Promise<User[]> {
return this.usersRepository.find(options)
}
- findWhere(where: Record<string, unknown>): Promise<User[]> {
- return this.usersRepository.find({ where })
- }
-
validatePassword(pass: string): void {
const err = []
if (_isEmpty(pass)) {
@@ -304,22 +282,14 @@ export class UserService {
})
}
- public async deleteRefreshTokensWhere(where: Record<string, unknown>) {
- await this.refreshTokenRepository.delete(where)
+ public async deleteRefreshTokensWhere(criteria: Record<string, unknown>) {
+ await this.refreshTokenRepository.delete(criteria)
}
public async findUserByApiKey(apiKey: string) {
return this.usersRepository.findOne({ where: { apiKey } })
}
- async getUser(id: string) {
- return this.usersRepository.findOne({ where: { id } })
- }
-
- async getUserByEmail(email: string) {
- return this.usersRepository.findOne({ where: { email } })
- }
-
async getUserByTelegramId(telegramId: string | number) {
return this.usersRepository.findOne({
where: { telegramChatId: telegramId.toString() },
@@ -375,7 +345,7 @@ export class UserService {
}
async previewSubscription(id: string, planID: number) {
- const user = await this.findOneWhere({ id })
+ const user = await this.findOne({ where: { id } })
const plan = this.getPlanById(planID)
if (!plan) {
@@ -436,7 +406,7 @@ export class UserService {
}
async updateSubscription(id: string, planID: number) {
- const user = await this.findOneWhere({ id })
+ const user = await this.findOne({ where: { id } })
const plan = this.getPlanById(planID)
if (!plan) {
@@ -510,7 +480,7 @@ export class UserService {
skip,
},
{
- user: user.id,
+ user: { id: user.id },
},
)
}
@@ -595,7 +565,7 @@ export class UserService {
}
async isRefCodeUnique(code: string): Promise<boolean> {
- const user = await this.findOneWhere({ refCode: code })
+ const user = await this.findOne({ where: { refCode: code } })
return !user
}
diff --git a/backend/apps/production/src/webhook/webhook.controller.ts b/backend/apps/production/src/webhook/webhook.controller.ts
index 397fb4e36..f948be4fb 100644
--- a/backend/apps/production/src/webhook/webhook.controller.ts
+++ b/backend/apps/production/src/webhook/webhook.controller.ts
@@ -130,7 +130,7 @@ export class WebhookController {
const currentUser = uid
? await this.userService.findOne({ where: { id: uid } })
- : await this.userService.findOneWhere({ email })
+ : await this.userService.findOne({ where: { email } })
const unlockDashboardParams =
body.alert_name === 'subscription_created' ||
isNextPlan(currentUser.planCode, plan.id)
@@ -178,8 +178,8 @@ export class WebhookController {
})
const { email } =
- (await this.userService.findOneWhere({
- subID,
+ (await this.userService.findOne({
+ where: { subID },
})) || {}
if (email) {
@@ -212,7 +212,9 @@ export class WebhookController {
balance_currency: balanceCurrency,
} = body
- const subscriber = await this.userService.findOneWhere({ subID })
+ const subscriber = await this.userService.findOne({
+ where: { subID },
+ })
if (!subscriber) {
this.logger.error(
@@ -240,8 +242,8 @@ export class WebhookController {
return
}
- const referrer = await this.userService.findOneWhere({
- id: subscriber.referrerID,
+ const referrer = await this.userService.findOne({
+ where: { id: subscriber.referrerID },
})
if (!referrer) {
@@ -271,8 +273,8 @@ export class WebhookController {
if (parseInt(attemptNumber, 10) >= MAX_PAYMENT_ATTEMPTS) {
const { email } =
- (await this.userService.findOneWhere({
- subID,
+ (await this.userService.findOne({
+ where: { subID },
})) || {}
if (!email) {
diff --git a/backend/apps/production/src/webhook/webhook.service.ts b/backend/apps/production/src/webhook/webhook.service.ts
index 97bb6bd44..efc510c64 100644
--- a/backend/apps/production/src/webhook/webhook.service.ts
+++ b/backend/apps/production/src/webhook/webhook.service.ts
@@ -143,8 +143,8 @@ export class WebhookService {
}
async unsubscribeByEmail(email: string): Promise<void> {
- const user = await this.userService.findOneWhere({
- email,
+ const user = await this.userService.findOne({
+ where: { email },
})
// checking if the bounce originates from admin email reports