Skip to content

Commit

Permalink
fix: database option for find one
Browse files Browse the repository at this point in the history
  • Loading branch information
andrechristikan committed Oct 3, 2024
1 parent 7081007 commit 13b9e43
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/modules/activity/services/activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
IDatabaseCreateOptions,
IDatabaseDeleteManyOptions,
IDatabaseFindAllOptions,
IDatabaseFindOneOptions,
IDatabaseGetTotalOptions,
IDatabaseOptions,
} from 'src/common/database/interfaces/database.interface';
import { ActivityCreateByAdminResponse } from 'src/modules/activity/dtos/request/activity.create-by-admin.response.dto';
import { ActivityCreateResponse } from 'src/modules/activity/dtos/request/activity.create.response.dto';
Expand Down Expand Up @@ -50,14 +50,14 @@ export class ActivityService implements IActivityService {

async findOneById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<ActivityDoc> {
return this.activityRepository.findOneById<ActivityDoc>(_id, options);
}

async findOne(
find: Record<string, any>,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<ActivityDoc> {
return this.activityRepository.findOne<ActivityDoc>(find, options);
}
Expand Down
10 changes: 5 additions & 5 deletions src/modules/api-key/services/api-key.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
IDatabaseCreateOptions,
IDatabaseDeleteManyOptions,
IDatabaseFindAllOptions,
IDatabaseFindOneOptions,
IDatabaseGetTotalOptions,
IDatabaseOptions,
IDatabaseSaveOptions,
IDatabaseUpdateManyOptions,
} from 'src/common/database/interfaces/database.interface';
Expand Down Expand Up @@ -54,28 +54,28 @@ export class ApiKeyService implements IApiKeyService {

async findOneById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<ApiKeyDoc> {
return this.apiKeyRepository.findOneById(_id, options);
}

async findOne(
find: Record<string, any>,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<ApiKeyDoc> {
return this.apiKeyRepository.findOne(find, options);
}

async findOneByKey(
key: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<ApiKeyDoc> {
return this.apiKeyRepository.findOne<ApiKeyDoc>({ key }, options);
}

async findOneByActiveKey(
key: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<ApiKeyDoc> {
return this.apiKeyRepository.findOne<ApiKeyDoc>(
{
Expand Down
12 changes: 6 additions & 6 deletions src/modules/country/services/country.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
IDatabaseCreateManyOptions,
IDatabaseDeleteManyOptions,
IDatabaseFindAllOptions,
IDatabaseFindOneOptions,
IDatabaseGetTotalOptions,
IDatabaseOptions,
} from 'src/common/database/interfaces/database.interface';
import { AwsS3Service } from 'src/modules/aws/services/aws.s3.service';
import { CountryCreateRequestDto } from 'src/modules/country/dtos/request/country.create.request.dto';
Expand Down Expand Up @@ -49,14 +49,14 @@ export class CountryService implements ICountryService {

async findOne(
find: Record<string, any>,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<CountryDoc> {
return this.countryRepository.findOne(find, options);
}

async findOneByName(
name: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<CountryDoc> {
return this.countryRepository.findOne(
DatabaseQueryContain('name', name),
Expand All @@ -66,7 +66,7 @@ export class CountryService implements ICountryService {

async findOneByAlpha2(
alpha2: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<CountryDoc> {
return this.countryRepository.findOne(
DatabaseQueryContain('alpha2Code', alpha2),
Expand All @@ -76,7 +76,7 @@ export class CountryService implements ICountryService {

async findOneByPhoneCode(
phoneCode: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<CountryDoc> {
return this.countryRepository.findOne(
{
Expand All @@ -88,7 +88,7 @@ export class CountryService implements ICountryService {

async findOneById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<CountryDoc> {
return this.countryRepository.findOneById(_id, options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
IDatabaseCreateOptions,
IDatabaseDeleteManyOptions,
IDatabaseFindAllOptions,
IDatabaseFindOneOptions,
IDatabaseGetTotalOptions,
IDatabaseOptions,
} from 'src/common/database/interfaces/database.interface';
import { HelperDateService } from 'src/common/helper/services/helper.date.service';
import { PasswordHistoryCreateByAdminRequestDto } from 'src/modules/password-history/dtos/request/password-history.create-by-admin.request.dto';
Expand Down Expand Up @@ -62,7 +62,7 @@ export class PasswordHistoryService implements IPasswordHistoryService {

async findOneById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<PasswordHistoryDoc> {
return this.passwordHistoryRepository.findOneById<PasswordHistoryDoc>(
_id,
Expand All @@ -72,7 +72,7 @@ export class PasswordHistoryService implements IPasswordHistoryService {

async findOne(
find: Record<string, any>,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<PasswordHistoryDoc> {
return this.passwordHistoryRepository.findOne<PasswordHistoryDoc>(
find,
Expand All @@ -83,7 +83,7 @@ export class PasswordHistoryService implements IPasswordHistoryService {
async findOneByUser(
user: string,
password: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<PasswordHistoryDoc> {
return this.passwordHistoryRepository.findOne<PasswordHistoryDoc>(
{
Expand All @@ -97,7 +97,7 @@ export class PasswordHistoryService implements IPasswordHistoryService {
async findOneUsedByUser(
user: string,
password: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<PasswordHistoryDoc> {
const today = this.helperDateService.create();

Expand Down
10 changes: 5 additions & 5 deletions src/modules/role/services/role.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
IDatabaseGetTotalOptions,
IDatabaseCreateManyOptions,
IDatabaseSaveOptions,
IDatabaseOptions,
IDatabaseDeleteManyOptions,
IDatabaseFindOneOptions,
} from 'src/common/database/interfaces/database.interface';
import { ENUM_POLICY_ROLE_TYPE } from 'src/modules/policy/enums/policy.enum';
import { RoleCreateRequestDto } from 'src/modules/role/dtos/request/role.create.request.dto';
Expand Down Expand Up @@ -82,28 +82,28 @@ export class RoleService implements IRoleService {

async findOneById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<RoleDoc> {
return this.roleRepository.findOneById(_id, options);
}

async findOne(
find: Record<string, any>,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<RoleDoc> {
return this.roleRepository.findOne(find, options);
}

async findOneByName(
name: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<RoleDoc> {
return this.roleRepository.findOne({ name }, options);
}

async findOneActiveById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<RoleDoc> {
return this.roleRepository.findOne({ _id, isActive: true }, options);
}
Expand Down
9 changes: 5 additions & 4 deletions src/modules/session/services/session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
IDatabaseCreateOptions,
IDatabaseDeleteManyOptions,
IDatabaseFindAllOptions,
IDatabaseFindOneOptions,
IDatabaseGetTotalOptions,
IDatabaseOptions,
IDatabaseUpdateManyOptions,
Expand Down Expand Up @@ -71,21 +72,21 @@ export class SessionService implements ISessionService {

async findOneById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<SessionDoc> {
return this.sessionRepository.findOneById<SessionDoc>(_id, options);
}

async findOne(
find: Record<string, any>,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<SessionDoc> {
return this.sessionRepository.findOne<SessionDoc>(find, options);
}

async findOneActiveById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<SessionDoc> {
const today = this.helperDateService.create();

Expand All @@ -103,7 +104,7 @@ export class SessionService implements ISessionService {
async findOneActiveByIdAndUser(
_id: string,
user: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<SessionDoc> {
const today = this.helperDateService.create();

Expand Down
8 changes: 4 additions & 4 deletions src/modules/setting/services/setting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
IDatabaseCreateOptions,
IDatabaseDeleteManyOptions,
IDatabaseFindAllOptions,
IDatabaseFindOneOptions,
IDatabaseGetTotalOptions,
IDatabaseOptions,
IDatabaseSaveOptions,
} from 'src/common/database/interfaces/database.interface';
import { ENUM_HELPER_DATE_FORMAT } from 'src/common/helper/enums/helper.enum';
Expand Down Expand Up @@ -53,21 +53,21 @@ export class SettingService implements ISettingService {

async findOne(
find: Record<string, any>,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<SettingDoc> {
return this.settingRepository.findOne(find, options);
}

async findOneById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<SettingDoc> {
return this.settingRepository.findOneById(_id, options);
}

async findOneByName(
name: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<SettingDoc> {
return this.settingRepository.findOne({ name }, options);
}
Expand Down
20 changes: 10 additions & 10 deletions src/modules/user/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
IDatabaseExistOptions,
IDatabaseFindAllAggregateOptions,
IDatabaseFindAllOptions,
IDatabaseFindOneOptions,
IDatabaseGetTotalOptions,
IDatabaseOptions,
IDatabaseSaveOptions,
IDatabaseUpdateOptions,
} from 'src/common/database/interfaces/database.interface';
Expand Down Expand Up @@ -190,29 +190,29 @@ export class UserService implements IUserService {

async findOneById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<UserDoc> {
return this.userRepository.findOneById<UserDoc>(_id, options);
}

async findOne(
find: Record<string, any>,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<UserDoc> {
return this.userRepository.findOne<UserDoc>(find, options);
}

async findOneByEmail(
email: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<UserDoc> {
return this.userRepository.findOne<UserDoc>({ email }, options);
}

async findOneByMobileNumber(
country: string,
mobileNumber: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<UserDoc> {
return this.userRepository.findOne<UserDoc>(
{
Expand All @@ -225,7 +225,7 @@ export class UserService implements IUserService {

async findOneWithRoleAndCountry(
find?: Record<string, any>,
options?: IDatabaseFindAllOptions
options?: IDatabaseFindOneOptions
): Promise<IUserDoc> {
return this.userRepository.findOne<IUserDoc>(find, {
...options,
Expand All @@ -235,7 +235,7 @@ export class UserService implements IUserService {

async findOneWithRoleAndCountryById(
_id: string,
options?: IDatabaseFindAllOptions
options?: IDatabaseFindOneOptions
): Promise<IUserDoc> {
return this.userRepository.findOneById<IUserDoc>(_id, {
...options,
Expand Down Expand Up @@ -271,7 +271,7 @@ export class UserService implements IUserService {

async findOneActiveById(
_id: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<IUserDoc> {
return this.userRepository.findOne<IUserDoc>(
{ _id, status: ENUM_USER_STATUS.ACTIVE },
Expand All @@ -284,7 +284,7 @@ export class UserService implements IUserService {

async findOneActiveByEmail(
email: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<IUserDoc> {
return this.userRepository.findOne<IUserDoc>(
{ email, status: ENUM_USER_STATUS.ACTIVE },
Expand All @@ -298,7 +298,7 @@ export class UserService implements IUserService {
async findOneActiveByMobileNumber(
country: string,
mobileNumber: string,
options?: IDatabaseOptions
options?: IDatabaseFindOneOptions
): Promise<IUserDoc> {
return this.userRepository.findOne<IUserDoc>(
{
Expand Down

0 comments on commit 13b9e43

Please sign in to comment.