Skip to content

Commit

Permalink
Merge branch 'develop-x' of https://github.com/inflection-zone/reanca…
Browse files Browse the repository at this point in the history
…re-service into develop-x
  • Loading branch information
Priyanka-Inflectionzone committed Feb 2, 2024
2 parents 73cfcae + fa5add3 commit 8d8f7c5
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 115 deletions.
64 changes: 32 additions & 32 deletions src/api/users/user/user.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ export class UserValidator {
.isNumeric()
.run(request);

await oneOf([
body('TenantId')
.trim()
.isUUID(),
body('TenantCode')
.trim()
.escape(),
]).run(request);
// await oneOf([
// body('TenantId')
// .trim()
// .isUUID(),
// body('TenantCode')
// .trim()
// .escape(),
// ]).run(request);

const result = validationResult(request);
if (!result.isEmpty()) {
Expand Down Expand Up @@ -392,14 +392,14 @@ export class UserValidator {
.escape(),
]).run(request);

await oneOf([
body('TenantId').exists()
.trim()
.isUUID(),
body('TenantCode').exists()
.trim()
.escape(),
]).run(request);
// await oneOf([
// body('TenantId').exists()
// .trim()
// .isUUID(),
// body('TenantCode').exists()
// .trim()
// .escape(),
// ]).run(request);

await body('NewPassword').exists()
.trim()
Expand Down Expand Up @@ -447,14 +447,14 @@ export class UserValidator {
.escape(),
]).run(request);

await oneOf([
body('TenantId').exists()
.trim()
.isUUID(),
body('TenantCode').exists()
.trim()
.escape(),
]).run(request);
// await oneOf([
// body('TenantId').exists()
// .trim()
// .isUUID(),
// body('TenantCode').exists()
// .trim()
// .escape(),
// ]).run(request);

await body('Purpose').optional()
.trim()
Expand Down Expand Up @@ -528,14 +528,14 @@ export class UserValidator {
.isNumeric()
.run(request);

await oneOf([
body('TenantId').exists()
.trim()
.isUUID(),
body('TenantCode').exists()
.trim()
.escape(),
]).run(request);
// await oneOf([
// body('TenantId').exists()
// .trim()
// .isUUID(),
// body('TenantCode').exists()
// .trim()
// .escape(),
// ]).run(request);

const result = validationResult(request);
if (!result.isEmpty()) {
Expand Down
1 change: 1 addition & 0 deletions src/auth/custom/custom.user.authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class CustomUserAuthenticator implements IUserAuthenticator {
UserId : user.id,
TenantId : tenant.id,
TenantCode : tenant.Code,
TenantName : tenant.Name,
DisplayName : user.Person.DisplayName,
Phone : user.Person.Phone,
Email : user.Person.Email,
Expand Down
10 changes: 9 additions & 1 deletion src/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { generate } from 'generate-password';
import mime = require('mime-types');
import path from 'path';
import { ConfigurationManager } from '../config/configuration.manager';
import { Gender, OSType } from '../domain.types/miscellaneous/system.types';
import { Gender, OSType, uuid } from '../domain.types/miscellaneous/system.types';
import { InputValidationError } from './input.validation.error';
import { TimeHelper } from './time.helper';
import Countries from './misc/countries';
Expand Down Expand Up @@ -770,4 +770,12 @@ export class Helper {
}
};

public static constructFileDownloadURL = (fileResourceId: uuid): string => {
if (!fileResourceId) {
return null;
}
const url = ConfigurationManager.BaseUrl() + '/api/v1/file-resources/' + fileResourceId + '/download';
return url;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface IUserRepo {

getById(id: uuid): Promise<UserDetailsDto>;

getByPersonId(personId: uuid): Promise<UserDetailsDto>;

updateLastLogin(id: uuid): Promise<void>;

delete(id: uuid): Promise<boolean>;
Expand Down
3 changes: 3 additions & 0 deletions src/database/sql/sequelize/mappers/person/person.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class PersonMapper {

const age = Helper.getAgeFromBirthDate(person.BirthDate);

const profileImageURL = Helper.constructFileDownloadURL(person.ImageResourceId);

const dto: PersonDetailsDto = {
id : person.id,
Prefix : person.Prefix,
Expand All @@ -36,6 +38,7 @@ export class PersonMapper {
Email : person.Email,
TelegramChatId : person.TelegramChatId,
ImageResourceId : person.ImageResourceId,
ProfileImageURL : profileImageURL,
ActiveSince : person.CreatedAt,
Roles : [],
Addresses : []
Expand Down
7 changes: 5 additions & 2 deletions src/database/sql/sequelize/mappers/users/user/user.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import User from '../../../models/users/user/user.model';
import { PersonDetailsDto, PersonDto } from '../../../../../../domain.types/person/person.dto';
import { UserDetailsDto, UserDto } from '../../../../../../domain.types/users/user/user.dto';
import Tenant from '../../../models/tenant/tenant.model';
import Role from '../../../models/role/role.model';

///////////////////////////////////////////////////////////////////////////////////

export class UserMapper {

static toDetailsDto = (user: User, tenant: Tenant = null, personDto: PersonDetailsDto = null)
static toDetailsDto = (user: User, tenant: Tenant = null, personDto: PersonDetailsDto = null, role: Role = null)
: UserDetailsDto => {

if (user == null){
Expand All @@ -19,13 +20,15 @@ export class UserMapper {
UserName : user.UserName,
PersonId : user.PersonId,
TenantId : user.TenantId ?? tenant?.id,
TenantCode : tenant?.Code,
TenantName : tenant?.Name,
Person : personDto,
IsTestUser : user.IsTestUser,
LastLogin : user.LastLogin,
DefaultTimeZone : user.DefaultTimeZone,
CurrentTimeZone : user.CurrentTimeZone,
RoleId : user.RoleId,
Role : null
Role : role ?? null,
};
return dto;
};
Expand Down
17 changes: 17 additions & 0 deletions src/database/sql/sequelize/repositories/users/user/user.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Tenant from '../../../models/tenant/tenant.model';
import { uuid } from '../../../../../../domain.types/miscellaneous/system.types';
import { TenantMapper } from '../../../mappers/tenant/tenant.mapper';
import { TenantDto } from '../../../../../../domain.types/tenant/tenant.dto';
import { PersonMapper } from '../../../mappers/person/person.mapper';
import Role from '../../../models/role/role.model';

///////////////////////////////////////////////////////////////////////////////////

Expand All @@ -33,6 +35,21 @@ export class UserRepo implements IUserRepo {
return null;
};

getByPersonId = async (personId: string): Promise<UserDetailsDto> => {
try {
const user = await User.findOne({ where: { PersonId: personId } });
const tenant = await Tenant.findByPk(user.TenantId);
const person = await Person.findByPk(personId);
const role = await Role.findByPk(user.RoleId);
const personDto = await PersonMapper.toDetailsDto(person);
return UserMapper.toDetailsDto(user, tenant, personDto, role);
}
catch (error) {
Logger.instance().log(error.message);
throw new ApiError(500, error.message);
}
};

getByEmailAndRole = async (email: any, roleId: number): Promise<UserDetailsDto> => {

const person = await Person.findOne({
Expand Down
1 change: 1 addition & 0 deletions src/domain.types/miscellaneous/current.user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface CurrentUser {
UserId : string;
TenantId : string;
TenantCode : string;
TenantName : string;
DisplayName : string;
Phone : string;
Email : string;
Expand Down
1 change: 1 addition & 0 deletions src/domain.types/person/person.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface PersonDetailsDto {
LivingAlone? : boolean;
WorkedPriorToStroke? : boolean;
ImageResourceId : string;
ProfileImageURL ?: string;
Roles : PersonRoleDto[];
ActiveSince : Date;
Addresses : AddressDto[];
Expand Down
2 changes: 2 additions & 0 deletions src/domain.types/users/user/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface UserDetailsDto {
id : uuid;
PersonId : uuid;
TenantId : uuid;
TenantCode ?: string;
TenantName ?: string;
Person : PersonDetailsDto;
RoleId : number;
Role : RoleDto;
Expand Down
8 changes: 3 additions & 5 deletions src/services/community/user.group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { uuid } from "../../domain.types/miscellaneous/system.types";
import { Logger } from "../../common/logger";
import axios from 'axios';
import { IUserRepo } from "../../database/repository.interfaces/users/user/user.repo.interface";
import { ConfigurationManager } from "../../config/configuration.manager";
import { Helper } from "../../common/helper";

////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -238,10 +238,8 @@ export class UserGroupService {
const user = await this._userRepo.getById(userId);
const clientId = await this.getClientId();
const fileResourceId = user.Person.ImageResourceId;
var profileImageUrl: string | null | undefined = null;
if (fileResourceId) {
profileImageUrl = ConfigurationManager.BaseUrl() + '/api/v1/file-resources/' + fileResourceId + '/download';
}
var profileImageUrl = Helper.constructFileDownloadURL(fileResourceId);

url = process.env.AWARDS_SERVICE_BASE_URL + '/api/v1/participants';
var body = {
clientId : clientId,
Expand Down
1 change: 1 addition & 0 deletions src/services/users/patient/patient.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class PatientService {
UserId : items[0].id,
TenantId : tenant.id,
TenantCode : tenant.Code,
TenantName : tenant.Name,
DisplayName : items[0].DisplayName,
Phone : items[0].Phone,
Email : items[0].Email,
Expand Down
Loading

0 comments on commit 8d8f7c5

Please sign in to comment.