Skip to content

Commit

Permalink
Merge pull request #119 from souravbhowmik1999/formCreate
Browse files Browse the repository at this point in the history
Get Tenant form related changes
  • Loading branch information
Shubham4026 authored Dec 18, 2024
2 parents 9499086 + c0ea73a commit 073300f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
9 changes: 8 additions & 1 deletion src/forms/forms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ export class FormsService {
HttpStatus.BAD_REQUEST
);
}


const { context, contextType, tenantId } = requiredData;
const validationResult = await this.validateFormInput(requiredData);

if (validationResult.error) {
return APIResponse.error(
response,
Expand Down Expand Up @@ -160,6 +163,7 @@ export class FormsService {

if (context) {
const validContextTypes = await this.getValidContextTypes(context);

if (validContextTypes.length === 0) {
return { error: `Invalid context: ${context}` };
}
Expand All @@ -175,14 +179,17 @@ export class FormsService {
return { error: null };
}

private async getValidContextTypes(context: string): Promise<string[]> {

private async getValidContextTypes(context: string): Promise<string[]> {
switch (context.toLowerCase()) {
case "users":
return await this.getUserContextTypesFromDB();
case "cohorts":
return Object.values(CohortContextType);
case "cohortmember":
return ["COHORTMEMBER"];
case "tenant":
return ["TENANT"];
default:
return [];
}
Expand Down
6 changes: 3 additions & 3 deletions src/tenant/dto/tenant-update.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export class TenantUpdateDto {
@ApiPropertyOptional({
type: String,
description: "Status of the tenant",
enum: ['active', 'inactive', 'archive'],
enum: ['active', 'inactive', 'archived'],
default: 'active',
})
@IsString()
@IsOptional()
@IsIn(['active', 'inactive', 'archive'])
@IsIn(['active', 'inactive', 'archived'])
@Expose()
status: 'active' | 'inactive' | 'archive';
status: 'active' | 'inactive' | 'archived';

@Expose()
@IsString()
Expand Down
4 changes: 2 additions & 2 deletions src/tenant/entities/tenent.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class Tenant {
@Column({
type: 'text',
default: 'active',
enum: ['active', 'inactive', 'archive'],
enum: ['active', 'inactive', 'archived'],
})
status: 'active' | 'inactive' | 'archive'; // Status column with enum values
status: 'active' | 'inactive' | 'archived'; // Status column with enum values

@Column("int4", { nullable: false })
@Min(0)
Expand Down
29 changes: 16 additions & 13 deletions src/tenant/tenant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,24 @@ export class TenantService {
);
}

let checkExistingTenantName = await this.tenantRepository.findOne({
where: {
"name": tenantUpdateDto?.name
if(tenantUpdateDto.name){
const checkExistingTenantName = await this.tenantRepository.findOne({
where: {
"name": tenantUpdateDto.name
}
})
if (checkExistingTenantName) {
return APIResponse.error(
response,
apiId,
API_RESPONSES.CONFLICT,
API_RESPONSES.TENANT_EXISTS,
HttpStatus.CONFLICT
);
}
})

if (checkExistingTenantName) {
return APIResponse.error(
response,
apiId,
API_RESPONSES.CONFLICT,
API_RESPONSES.TENANT_EXISTS,
HttpStatus.CONFLICT
);
}



let result = await this.tenantRepository.update(tenantId, tenantUpdateDto);
return APIResponse.success(
Expand Down

0 comments on commit 073300f

Please sign in to comment.