Skip to content

Commit

Permalink
provider and tocket fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed May 12, 2024
1 parent 517b7a0 commit 2aad700
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/features/children/children.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { SyncService } from '../sync/sync.service';
import { LocationEntity } from 'src/entities/location.entity';
import { NgoParams } from 'src/types/parameters/NgoParammeters';
import {
captilizeFirstLetter as capitalizeFirstLetter,
capitalizeFirstLetter,
convertFlaskToSayAppRoles,
convertFlaskToSayRoles,
truncateString,
Expand Down
6 changes: 4 additions & 2 deletions src/features/need/need.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,11 @@ export class NeedController {
message: validatedNeed.message,
from: superAdmin.flaskUserId,
announcement: validatedNeed.ticketDetails.lastAnnouncement,
color: validatedNeed.ticketDetails.color,
},
ticket,
);
// Disable notification for admin
await this.ticketService.createTicketView(
superAdmin.flaskUserId,
ticket.id,
Expand All @@ -350,8 +352,8 @@ export class NeedController {
ticketError &&
daysDifference(ticketError.createdAt, new Date()) > GRACE_PERIOD
) {
console.log('\x1b[36m%s\x1b[0m', 'Deleting need...\n');
//delete
// when we use panel we take care of this in the taskCard component
console.log('\x1b[36m%s\x1b[0m', 'Need will be deleted from front-end...\n');
}
toBeConfirmed.list.push({
limit: null,
Expand Down
12 changes: 11 additions & 1 deletion src/features/provider/provider.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
BadRequestException,
Body,
Controller,
Delete,
Expand Down Expand Up @@ -40,7 +41,7 @@ import { isAuthenticated } from 'src/utils/auth';
@ApiTags('Provider')
@Controller('providers')
export class ProviderController {
constructor(private providerService: ProviderService) { }
constructor(private providerService: ProviderService) {}

@Get(`all`)
@ApiSecurity('flask-access-token')
Expand Down Expand Up @@ -136,7 +137,16 @@ export class ProviderController {
if (!isAuthenticated(panelFlaskUserId, panelFlaskTypeId)) {
throw new ForbiddenException('You Are not authorized');
}

let provider: ProviderEntity;
provider = await this.providerService.getProviderByName(request.name);
if (
provider &&
provider.city == request.city &&
provider.country == request.country
) {
throw new BadRequestException('Already exist!');
}
const newProvider = {
name: request.name,
description: request?.description,
Expand Down
164 changes: 88 additions & 76 deletions src/features/provider/provider.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,105 @@ import { Repository } from 'typeorm';
import { ProviderParams } from '../../types/parameters/ProviderParams';
import { from, Observable } from 'rxjs';
import { ProviderJoinNeedEntity } from 'src/entities/provider.Join.need..entity';

import { capitalizeFirstLetter } from 'src/utils/helpers';

@Injectable()
export class ProviderService {
constructor(
@InjectRepository(ProviderEntity)
private providerRepository: Repository<ProviderEntity>,
@InjectRepository(ProviderJoinNeedEntity)
private providerJoinNeedRepository: Repository<ProviderJoinNeedEntity>,
constructor(
@InjectRepository(ProviderEntity)
private providerRepository: Repository<ProviderEntity>,
@InjectRepository(ProviderJoinNeedEntity)
private providerJoinNeedRepository: Repository<ProviderJoinNeedEntity>,
) {}

) { }
async getProviders(): Promise<ProviderEntity[]> {
return this.providerRepository.find({
relations: {
needs: true,
},
order: {
createdAt: 'DESC',
},
});
}

async getProviders(
): Promise<ProviderEntity[]> {
return this.providerRepository.find()
}
getProviderById(id: string): Promise<ProviderEntity> {
const provider = this.providerRepository.findOne({
where: {
id,
},
});
return provider;
}

getProviderById(id: string): Promise<ProviderEntity> {
const provider = this.providerRepository.findOne({
where: {
id,
}
});
return provider;
getProviderByName(name: string): Promise<ProviderEntity> {
let provider = this.providerRepository.findOne({
where: {
name,
},
});
if (!provider) {
provider = this.providerRepository.findOne({
where: {
name: name.toLowerCase(),
},
});
}

getProviderByName(name: string): Promise<ProviderEntity> {
const provider = this.providerRepository.findOne({
where: {
name,
}
});
return provider;
if (!provider) {
provider = this.providerRepository.findOne({
where: {
name: capitalizeFirstLetter(name),
},
});
}
return provider;
}

// --------------------------------- to add providers for older needs before panel version 2.0.0 ----------------------------------------------- //

async getProviderNeedRelationById(flaskNeedId: number): Promise<ProviderJoinNeedEntity> {
return await this.providerJoinNeedRepository.findOne({
where: {
flaskNeedId,
}
});

}
// --------------------------------- to add providers for older needs before panel version 2.0.0 ----------------------------------------------- //

createRelation(
flaskNeedId: number,
nestProviderId: string,
): Promise<ProviderJoinNeedEntity> {
const newProvider = this.providerJoinNeedRepository.create({
flaskNeedId, nestProviderId
});
return this.providerJoinNeedRepository.save(newProvider);
}
// -------------------------------------------------------------------------------- //
createProvider(
providerDetails: ProviderParams,
): Promise<ProviderEntity> {
const newProvider = this.providerRepository.create({
name: providerDetails.name,
description: providerDetails.description,
address: providerDetails.address,
type: providerDetails.type,
typeName: providerDetails.typeName,
website: providerDetails.website,
city: providerDetails.city,
state: providerDetails.state,
country: providerDetails.country,
logoUrl: providerDetails.logoUrl,
isActive: providerDetails.isActive,
});
return this.providerRepository.save(newProvider);
}
async getProviderNeedRelationById(
flaskNeedId: number,
): Promise<ProviderJoinNeedEntity> {
return await this.providerJoinNeedRepository.findOne({
where: {
flaskNeedId,
},
});
}

updateProvider(
id: string,
updateProviderDetails: ProviderParams,
) {
return this.providerRepository.update(
id,
{ ...updateProviderDetails },
);
}
createRelation(
flaskNeedId: number,
nestProviderId: string,
): Promise<ProviderJoinNeedEntity> {
const newProvider = this.providerJoinNeedRepository.create({
flaskNeedId,
nestProviderId,
});
return this.providerJoinNeedRepository.save(newProvider);
}
// -------------------------------------------------------------------------------- //
createProvider(providerDetails: ProviderParams): Promise<ProviderEntity> {
const newProvider = this.providerRepository.create({
name: providerDetails.name,
description: providerDetails.description,
address: providerDetails.address,
type: providerDetails.type,
typeName: providerDetails.typeName,
website: providerDetails.website,
city: providerDetails.city,
state: providerDetails.state,
country: providerDetails.country,
logoUrl: providerDetails.logoUrl,
isActive: providerDetails.isActive,
});
return this.providerRepository.save(newProvider);
}

deleteOne(id: number): Observable<any> {
return from(this.providerRepository.delete(id));
}
updateProvider(id: string, updateProviderDetails: ProviderParams) {
return this.providerRepository.update(id, { ...updateProviderDetails });
}

deleteOne(id: number): Observable<any> {
return from(this.providerRepository.delete(id));
}
}
2 changes: 1 addition & 1 deletion src/features/ticket/ticket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class TicketService {
): Promise<TicketEntity> {
const newTicket = this.ticketRepository.create({
...ticketDetails,
color: Colors.YELLOW, // start with Warning,
color: !ticketDetails.color ? Colors.YELLOW : ticketDetails.color, // start with Warning,
});

newTicket.contributors = participants;
Expand Down
3 changes: 2 additions & 1 deletion src/types/parameters/CreateTicketContentParameters.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AnnouncementEnum } from "../interfaces/interface"
import { AnnouncementEnum, Colors } from "../interfaces/interface"

export class CreateTicketContentParams {
from: number
message: string
announcement: AnnouncementEnum
announcedArrivalDate?: Date
color?: Colors |null
}
17 changes: 9 additions & 8 deletions src/types/parameters/CreateTicketParameters.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { NeedEntity } from "src/entities/need.entity"
import { AnnouncementEnum } from "../interfaces/interface"
import { NeedEntity } from 'src/entities/need.entity';
import { AnnouncementEnum, Colors } from '../interfaces/interface';

export class CreateTicketParams {
title: string
need: NeedEntity
role: number
flaskUserId: number
flaskNeedId: number
lastAnnouncement: AnnouncementEnum
title: string;
need: NeedEntity;
role: number;
flaskUserId: number;
flaskNeedId: number;
lastAnnouncement: AnnouncementEnum;
color?: Colors | null;
}
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ export function shuffleArray(array: any[]) {
return array;
}

export function captilizeFirstLetter(word: string) {
export function capitalizeFirstLetter(word: string) {
return word.charAt(0).toUpperCase() + word.slice(1);
}

Expand Down
10 changes: 10 additions & 0 deletions src/utils/needConfirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ServerError } from 'src/filters/server-exception.filter';
import {
AnnouncementEnum,
CategoryEnum,
Colors,
FlaskUserTypesEnum,
NeedTypeEnum,
PaymentStatusEnum,
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function validateNeed(
flaskUserId: SUPER_ADMIN_ID,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SUPER_ADMIN),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};
result = {
needId: nestNeed.id,
Expand Down Expand Up @@ -120,6 +122,7 @@ export async function validateNeed(
flaskUserId: nestNeed.socialWorker.flaskUserId,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SOCIAL_WORKER),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};
result = {
needId: nestNeed.id,
Expand All @@ -145,6 +148,7 @@ export async function validateNeed(
flaskUserId: SUPER_ADMIN_ID,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SUPER_ADMIN),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};

result = {
Expand All @@ -164,6 +168,7 @@ export async function validateNeed(
flaskUserId: SUPER_ADMIN_ID,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SUPER_ADMIN),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};

result = {
Expand All @@ -183,6 +188,7 @@ export async function validateNeed(
flaskUserId: nestNeed.socialWorker.flaskUserId,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SOCIAL_WORKER),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};
console.log('\x1b[36m%s\x1b[0m', 'Creating Social workerTicket ...\n');
result = {
Expand Down Expand Up @@ -210,6 +216,7 @@ export async function validateNeed(
flaskUserId: SUPER_ADMIN_ID,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SUPER_ADMIN),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};

result = {
Expand All @@ -230,6 +237,7 @@ export async function validateNeed(
flaskUserId: SUPER_ADMIN_ID,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SUPER_ADMIN),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};
result = {
needId: nestNeed.id,
Expand All @@ -248,6 +256,7 @@ export async function validateNeed(
flaskUserId: nestNeed.socialWorker.flaskUserId,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SOCIAL_WORKER),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};
console.log('\x1b[36m%s\x1b[0m', 'Creating Auditor Ticket ...\n');
result = {
Expand Down Expand Up @@ -284,6 +293,7 @@ export async function validateNeed(
flaskUserId: nestNeed.socialWorker.flaskUserId,
role: convertFlaskToSayRoles(FlaskUserTypesEnum.SOCIAL_WORKER),
lastAnnouncement: AnnouncementEnum.ERROR,
color: Colors.RED,
};
result = {
needId: nestNeed.id,
Expand Down

0 comments on commit 2aad700

Please sign in to comment.