add : reseller

This commit is contained in:
2026-04-13 11:57:13 +03:30
parent fccea733e3
commit bb42b393c4
13 changed files with 152 additions and 21 deletions
+44 -1
View File
@@ -1,4 +1,4 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { UsersService } from '../users/providers/users.service';
import { CreateResellerDto } from './dto/create-reseller.dto';
import { ResellerRepository } from './repositories/reseller.repository';
@@ -37,4 +37,47 @@ export class ResellerService {
}
})
}
async finResellerAgents(userId: string) {
const reseller = await this.FindOneOrFailByUserId(userId)
return reseller.agents
}
async FindOneOrFailByUserId(userId: string) {
const reseller = await this.resellerRepository.findOne({
where: { owner: { id: userId } },
relations: { agents: true }
})
if (!reseller) {
throw new NotFoundException()
}
return reseller
}
async createResellerAgent(userId: string, userTobeAgent: string) {
const reseller = await this.FindOneOrFailByUserId(userId)
const { user } = await this.usersService.findOneById(userTobeAgent)
user.reseller = reseller
await this.usersService.save(user)
return user
}
async removeResellerAgent(userId: string, agentToBeDeleted: string) {
await this.FindOneOrFailByUserId(userId)
const { user } = await this.usersService.findOneById(agentToBeDeleted)
user.reseller = undefined
await this.usersService.save(user)
return user
}
}