Browse Source

Merge branch 'date-of-birth-string' into 'stage'

CHORE | Add field dateOfBirthStr to userInfo entity

See merge request jetup/rws/api-rws!246
merge-requests/247/head
Coder 2 years ago
parent
commit
91b3c45c0e
  1. 6
      src/core/namespaces/users.namespace.ts
  2. 4
      src/domain/users/classes/user-creator.ts
  3. 3
      src/domain/users/entities/user-info.entity.ts
  4. 6
      src/domain/users/services/users-list.service.ts
  5. 24
      src/domain/users/services/users.service.ts
  6. 3
      src/rest/admin/contacts/dto/get-contacts-list.dto.ts
  7. 11
      src/rest/admin/users/services/admin-users.service.ts

6
src/core/namespaces/users.namespace.ts

@ -104,9 +104,12 @@ export namespace Users { @@ -104,9 +104,12 @@ export namespace Users {
/** Внутрішній номер телефону */
innerPhoneNumber?: string
/** Дата народження */
/** Дата народження в числовому форматі (рік, місяць та число)*/
dateOfBirth: string
/** Дата народження в текстовому форматі (число та назва місяця)*/
dateOfBirthStr?: string
/** Посилання на зображення користувача */
avatarUrl?: string
@ -243,6 +246,7 @@ export namespace Users { @@ -243,6 +246,7 @@ export namespace Users {
loginOnMobileDate?: string
factories?: string
dateOfBirth?: string
dateOfBirthStr?: string
withFactoriesRelations?: boolean
globalSearchString?: string
searchFields?: (keyof Partial<UserModel & Info>)[]

4
src/domain/users/classes/user-creator.ts

@ -7,6 +7,7 @@ import { @@ -7,6 +7,7 @@ import {
UserAlreadyExistsException,
} from 'src/shared'
import { Repository } from 'typeorm'
import * as moment from 'moment'
type Payload = Omit<Users.SaveUserPayload, 'avatar' & 'factoryId'> & {
passwordSalt: string
@ -75,6 +76,9 @@ export class UserCreator { @@ -75,6 +76,9 @@ export class UserCreator {
middleName: this.payload.middleName,
position: this.payload.position,
dateOfBirth: this.payload.dateOfBirth,
dateOfBirthStr: this.payload.dateOfBirth
? moment(this.payload.dateOfBirth).locale('uk').format('DD MMMM')
: this.payload.dateOfBirth,
avatarUrl: this.payload.avatarUrl,
innerPhoneNumber: this.payload.innerPhoneNumber,
personalPhoneNumber: this.payload.personalPhoneNumber,

3
src/domain/users/entities/user-info.entity.ts

@ -34,6 +34,9 @@ export class UserInfo implements Users.Info { @@ -34,6 +34,9 @@ export class UserInfo implements Users.Info {
@Column({ type: 'date', nullable: true })
dateOfBirth: string
@Column({ nullable: true, select: false })
dateOfBirthStr: string
@Column({ nullable: true })
avatarUrl?: string

6
src/domain/users/services/users-list.service.ts

@ -311,6 +311,12 @@ export class UsersListService { @@ -311,6 +311,12 @@ export class UsersListService {
.andWhere('EXTRACT(MONTH FROM DATE(info.dateOfBirth)) = :month', { month })
}
if (params.dateOfBirthStr) {
query.andWhere('info.dateOfBirthStr ILIKE :dateOfBirthStr', {
dateOfBirthStr: `%${params.dateOfBirthStr}%`,
})
}
if (params.appType) {
if (params.appType === Users.AppType.Mobile) {
query.andWhere('it.loginOnMobileDate IS NOT NULL')

24
src/domain/users/services/users.service.ts

@ -45,6 +45,26 @@ export class UsersService implements Users.IUsersService { @@ -45,6 +45,26 @@ export class UsersService implements Users.IUsersService {
private readonly eventEmitter: EventEmitter2,
) {}
async onModuleInit() {
const users = await this.infoRepository
.createQueryBuilder('it')
.where('it.dateOfBirthStr IS NULL')
.select('it.userId')
.addSelect('it.dateOfBirth')
.getMany()
if (_.isEmpty(users)) return
await Promise.all(
users.map(async it => {
if (!it.dateOfBirth) return
const dateOfBirthStr = moment(it.dateOfBirth).locale('uk').format('DD MMMM')
await this.infoRepository.update({ userId: it.userId }, { dateOfBirthStr })
}),
)
}
public async save(payload: Users.SaveUserPayload, userId?: number, notValidateLogin?: boolean) {
await this.validateSavedData(payload)
@ -215,6 +235,10 @@ export class UsersService implements Users.IUsersService { @@ -215,6 +235,10 @@ export class UsersService implements Users.IUsersService {
dataToUpdateInfo.innerPhoneNumber = null
if (dataToUpdateInfo.personalPhoneNumber === 'deleted')
dataToUpdateInfo.personalPhoneNumber = null
if (dataToUpdateInfo.dateOfBirth)
dataToUpdateInfo.dateOfBirthStr = moment(dataToUpdateInfo.dateOfBirth)
.locale('uk')
.format('DD MMMM')
if (_.has(payload, 'avatarUrl')) dataToUpdateInfo.avatarUrl = payload.avatarUrl

3
src/rest/admin/contacts/dto/get-contacts-list.dto.ts

@ -42,4 +42,7 @@ export class GetContactsListParamsDto { @@ -42,4 +42,7 @@ export class GetContactsListParamsDto {
@DtoPropertyOptional()
@IsNumberString()
factoryId: number
@DtoPropertyOptional({ type: String })
dateOfBirthStr?: string
}

11
src/rest/admin/users/services/admin-users.service.ts

@ -76,17 +76,6 @@ export class AdminUsersService { @@ -76,17 +76,6 @@ export class AdminUsersService {
constructor(private readonly eventEmitter: EventEmitter2) {}
// async onModuleInit() {
// const users = await this.usersRepository.find()
// users.map(async it => {
// const lastLogins = await this.activitiesService.getUserLastLogins(it.id)
// it.loginOnMobileDate = lastLogins.mobile?.createdAt || null
// it.loginOnDesktopDate = lastLogins.desktop?.createdAt || null
// await this.usersRepository.update(it.id, it)
// })
// }
public async getShortInfoUsersList(
pagination: IPagination,
params: FetchShortInfoUsersListDto,

Loading…
Cancel
Save