Skip to content

Commit

Permalink
Merge pull request #128 from Sourav-Tekdi/search_tenant
Browse files Browse the repository at this point in the history
PS-3252: Introduce Status field on program management
  • Loading branch information
Shubham4026 authored Jan 9, 2025
2 parents 5c8a6ab + 327ec47 commit 92f168d
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 127 deletions.
1 change: 1 addition & 0 deletions src/common/utils/api-id.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const APIID = {
TENANT_CREATE: "api.tenant.create",
TENANT_UPDATE: "api.tenant.update",
TENANT_DELETE: "api.tenant.delete",
TENANT_SEARCH: "api.tenant.search",
TENANT_LIST: "api.tenant.list",
SEND_OTP: "api.send.OTP",
VERIFY_OTP: "api.verify.OTP",
Expand Down
14 changes: 9 additions & 5 deletions src/common/utils/response.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const API_RESPONSES = {
SERVICE_UNAVAILABLE:
"Notification service is unreachable. Please try again later.",
INTERNAL_SERVER_ERROR: "Internal Server Error",
FORBIDDEN: "Forbidden",
ERROR: "Error occurred",
UNEXPECTED_ERROR: "An unexpected error occurred",
ACADEMICYEAR: "Academic Year Created Successfully",
Expand Down Expand Up @@ -63,8 +64,8 @@ export const API_RESPONSES = {
INVALID_CONTEXTTYPE: (context, validContextTypes) => `Invalid contextType. For the context '${context}', it must be one of: ${validContextTypes}`,
COHORTID_NOTFOUND_FOT_THIS_YEAR: (cohortId) => `Cohort with cohortId ${cohortId} does not exist for this academic year.`,
MAPPING_EXIST_BW_USER_AND_COHORT: (userId, cohortId) => `Mapping already exists for userId ${userId} and cohortId ${cohortId} for this academic year`,
COHORT_NOTMAPPED_WITH_USER: (removeCohortId, userId) => `CohortId ${removeCohortId} is not mapped to userId ${userId} for this academic year.`,
COHORT_STATUS_UPDATED_FOR_USER: (removeCohortId, userId) => `CohortId ${removeCohortId} status updated for This userId ${userId}`,
COHORT_NOTMAPPED_WITH_USER: (removeCohortId, userId) => `Cohort Id ${removeCohortId} is not mapped to user Id${userId}} for this academic year.`,
COHORT_STATUS_UPDATED_FOR_USER: (removeCohortId, userId) => `Cohort Id ${removeCohortId} status updated for This user Id${userId}}`,
ERROR_UPDATE_COHORTMEMBER: (userId, removeCohortId, error) => `Error updating cohort member with userId ${userId} and cohortId ${removeCohortId}: ${error}`,
ERROR_SAVING_COHORTMEMBER: (userId, cohortId, error) => `Error saving cohort member with userId ${userId} and cohortId ${cohortId}: ${error}`,
USER_NOTEXIST: (userId) => `User with userId ${userId} does not exist for this academic year.`,
Expand Down Expand Up @@ -94,11 +95,11 @@ export const API_RESPONSES = {
USER_GET_BY_USER_ID_SUCCESSFULLY: 'User details fetched successfully by userId',
USER_GET_BY_USER_ID_AND_TENANT_ID_SUCCESSFULLY: 'User details fetched successfully by userId and tenantId',
USER_GET_BY_EMAIL_AND_TENANT_ID_SUCCESSFULLY: 'User details fetched successfully by email and tenantId',
USER_CREATE_KEYCLOAK: 'User created successfully on keycloak',

//Create user
USER_CREATE_SUCCESSFULLY: `User created successfully`,
USER_CREATE_IN_DB: 'User created in user table successfully',
USER_CREATE_KEYCLOAK: 'User created successfully on ',
USER_CREATE_FAILED: 'User creation failed',
USER_CREATE_FAILED_WITH_ERROR: (error) => `User creation failed with error: ${error}`,
USER_CREATE_FAILED_WITH_ERROR_AND_EMAIL: (error, email) => `User creation failed with error: ${error}. Email: ${email}`,
Expand Down Expand Up @@ -144,16 +145,19 @@ export const API_RESPONSES = {
COHORT_DATA_RESPONSE: 'Fetch cohort data response',
COHORT_UPDATED_SUCCESSFULLY: 'Cohort updated successfully.',
TENANT_NOTFOUND: 'Tenant not found',

COHORTMEMBER_UPDATE_SUCCESSFULLY: "Cohort Member updated Successfully",

//Tenant
TENANT_GET: "Tenant fetched successfully.",
TENANT_NOT_FOUND: "Tenant does not exist",
TENANT_NOT_FOUND: "No tenants found matching the specified criteria.",
TENANT_EXISTS: "Tenant already exists",
TENANT_CREATE: "Tenant created successfully",
TENANT_UPDATE: "Tenant updated successfully",
TENANT_DELETE: "Tenant deleted successfully",
TENANT_SEARCH_SUCCESS: "Tenant search successfully",
TENANT_CREATE_FAILED: "Failed to create tenant, please try again.",
REQUIRED_AND_UUID: "tenantId is required and it's must be a valid UUID.",


//OTP
NOTIFICATION_FAIL_DURING_OTP_SEND: "Send SMS notification failed duing OTP send",
Expand Down
43 changes: 14 additions & 29 deletions src/tenant/dto/tenant-create.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,37 @@ export class TenantCreateDto {
updatedBy: string;

//tenant name
@ApiProperty({
type: String,
description: "Tenant name",
default: "",
})
@ApiProperty({ type: () => String })
@IsString()
@IsNotEmpty()
@Expose()
name: string;

//domain
@ApiPropertyOptional({
type: String,
description: "Domain Name",
default: "",
})
@Expose()
@ApiPropertyOptional({ type: () => String })
@IsString()
@IsOptional()
domain?: string;

//params
@ApiPropertyOptional({
type: Object,
description: "Params",
default: "",
})
@Expose()
params: object;
@ApiPropertyOptional({ type: () => Object })
@IsOptional()
params?: object;

//file path
@ApiPropertyOptional({
description: 'List of program images (URLs or other related strings)',
})
@Expose()
@ApiPropertyOptional({ type: () => [String] })
@IsArray()
@IsString({ each: true }) @IsOptional()
programImages: string[];

@ApiProperty({ type: String })
@ApiProperty({ type: () => String })
@IsString()
@IsNotEmpty()
@Expose()
description?: string;
description: string;

@ApiProperty({ type: String })
@ApiProperty({ type: () => String })
@IsString()
@IsNotEmpty()
@Expose()
programHead?: string
programHead: string;

constructor(obj?: Partial<TenantCreateDto>) {
if (obj) {
Expand Down
97 changes: 97 additions & 0 deletions src/tenant/dto/tenant-search.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import {
ArrayNotEmpty,
IsArray,
IsIn,
IsNotEmpty,
IsNumber,
IsObject,
IsOptional,
IsString,
IsUUID,
Max,
Min,
} from "class-validator";
import { Expose } from "class-transformer";

export class TenantFilters {
@ApiPropertyOptional({ type: () => String, description: 'Tenant Id must be a (UUID)' })
@IsString()
@IsUUID()
@IsOptional()
tenantId?: string;

@ApiPropertyOptional({ type: () => String })
@IsString()
@IsOptional()
name?: string;

@ApiPropertyOptional({ type: () => String })
@IsOptional()
@IsString()
domain?: string;

@ApiPropertyOptional({
type: [String],
description: "Status of the tenant",
enum: ['published', 'draft', 'archived'],
isArray: true,
default: ['published'],
})
@IsArray()
@IsOptional()
@ArrayNotEmpty() // Ensures the array is not empty (if provided)
@IsIn(['published', 'draft', 'archived'], { each: true }) // Validates each array element
@IsNotEmpty({ each: true }) // Ensures no empty strings in the array
@Expose()
status?: ('published' | 'draft' | 'archived')[];

@ApiPropertyOptional({ type: () => String, description: 'The ID of the creator (UUID)' })
@IsString()
@IsUUID()
@IsOptional()
createdBy?: string;

@ApiPropertyOptional({ type: () => String, description: 'The ID of the updater (UUID)' })
@IsString()
@IsUUID()
@IsOptional()
updatedBy?: string;

@ApiPropertyOptional({ type: () => String })
@IsString()
@IsOptional()
programHead?: string;
}

export class TenantSearchDTO {
@ApiProperty({
type: Number,
description: "Limit",
minimum: 1,
maximum: 200,
default: 10,
})
@IsNumber()
@Min(1)
@Max(200)
limit: number;

@ApiProperty({
type: Number,
description: "Offset",
minimum: 0,
maximum: 200,
default: 0,
})
@IsNumber()
@Min(0)
@Max(200)
offset: number;

@ApiPropertyOptional({ type: () => TenantFilters })
@IsOptional()
@IsObject()
@IsNotEmpty({ each: true })
filters?: TenantFilters;
}
55 changes: 18 additions & 37 deletions src/tenant/dto/tenant-update.dto.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,62 @@
import { Expose, Type } from "class-transformer";
import { Expose } from "class-transformer";
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsIn, IsNotEmpty, IsOptional, IsString } from "class-validator";

export class TenantUpdateDto {
//tenant name
@ApiPropertyOptional({
type: String,
description: "Tenant name",
default: "",
})
@ApiPropertyOptional({ type: () => String })
@IsString()
@IsOptional()
@Expose()
name: string;
name?: string;

//domain
@ApiPropertyOptional({
type: String,
description: "Domain Name",
default: "",
})
@ApiPropertyOptional({ type: () => String })
@IsOptional()
@Expose()
@IsString()
domain?: string;

//params
@ApiPropertyOptional({
type: Object,
description: "Params",
default: "",
})
@Expose()
@ApiPropertyOptional({ type: () => Object })
@IsOptional()
params?: object;

//file path
@ApiPropertyOptional({
type: String,
})
@ApiPropertyOptional({ type: () => [String] })
@IsOptional()
@Expose()
programImages: string[];
programImages?: string[];


@ApiPropertyOptional({ type: String })
@ApiPropertyOptional({ type: () => String })
@IsString()
@IsOptional()
@Expose()
description: string;
description?: string;


//status
@ApiPropertyOptional({
type: String,
description: "Status of the tenant",
enum: ['active', 'inactive', 'archived'],
default: 'active',
enum: ['published', 'draft', 'archived'],
default: 'published',
})
@IsString()
@IsOptional()
@IsIn(['active', 'inactive', 'archived'])
@IsIn(['published', 'draft', 'archived'])
@Expose()
status: 'active' | 'inactive' | 'archived';
status?: 'published' | 'draft' | 'archived';

@Expose()
@ApiPropertyOptional({ type: () => String })
@IsString()
@IsOptional()
createdBy: string;
createdBy?: string;

@Expose()
@IsString()
@IsOptional()
updatedBy: string;

@ApiPropertyOptional({ type: String })
@ApiPropertyOptional({ type: () => String })
@IsString()
@IsOptional()
@Expose()
programHead?: string;

constructor(obj?: Partial<TenantUpdateDto>) {
Expand Down
6 changes: 3 additions & 3 deletions src/tenant/entities/tenent.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export class Tenant {

@Column({
type: 'text',
default: 'active',
enum: ['active', 'inactive', 'archived'],
default: 'draft',
enum: ['published', 'draft', 'archived'],
})
status: 'active' | 'inactive' | 'archived'; // Status column with enum values
status: 'published' | 'draft' | 'archived'; // Status column with enum values

@Column("int4", { nullable: false })
@Min(0)
Expand Down
Loading

0 comments on commit 92f168d

Please sign in to comment.