Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
MigrationInterface,
QueryRunner,
TableColumn,
TableIndex,
} from 'typeorm';

export class AddStoreTypeDescription1761330903480
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumn(
'stores',
new TableColumn({
name: 'store_type_description',
type: 'text',
isNullable: true,
}),
);

await queryRunner.query(`
UPDATE stores
SET store_type_description = store_type
WHERE store_type IS NOT NULL
AND store_type != ''
AND store_type != 'OTHER'
`);

await queryRunner.query(`
UPDATE stores
SET store_type = 'OTHER'
WHERE store_type IS NOT NULL
`);

await queryRunner.query(`
UPDATE stores
SET store_type = 'OTHER',
store_type_description = 'Legacy store type - migrated from previous system'
WHERE store_type IS NULL OR store_type = ''
`);

await queryRunner.createIndex(
'stores',
new TableIndex({
columnNames: ['store_type'],
name: 'IDX_stores_store_type',
}),
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropIndex('stores', 'IDX_stores_store_type');

await queryRunner.query(`
UPDATE stores
SET store_type = store_type_description
WHERE store_type_description IS NOT NULL AND store_type_description != ''
`);

await queryRunner.dropColumn('stores', 'store_type_description');
}
}
2 changes: 1 addition & 1 deletion backend/src/modules/admin/admin.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('AdminService', () => {
id: '1',
name: 'Test Store',
address: '123 Main St',
storeType: 'Retail',
storeType: 'SHOP' as const,
latitude: 123.456,
longitude: 78.901,
localGovernment: {
Expand Down
43 changes: 42 additions & 1 deletion backend/src/modules/store/dto/store.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
IsOptional,
IsLatitude,
IsLongitude,
IsIn,
ValidateIf,
Length,
} from 'class-validator';
import { QueryValidator } from '~/helpers/query.helper';
import { StoreType } from '../types/store.interface';

export class StoreDto {
@IsString()
Expand All @@ -27,7 +31,27 @@

@IsString()
@IsNotEmpty()
storeType: string;
@IsIn([
'SHOP',
'REFUSE_SITE',
'SCHOOL',
'HOSPITAL',
'BAR_RESTAURANT',
'FUELING_STATION',
'HOTEL',
'RECREATION_PARK',
'FINANCIAL_INSTITUTION',
'RELIGIOUS',
'OTHER',
])
storeType: StoreType;

@IsString()
@IsOptional()
@Length(1, 500, { message: 'Store type description must be between 1 and 500 characters' })
@ValidateIf((o) => o.storeType === 'SHOP' || o.storeType === 'OTHER')
@IsNotEmpty()
storeTypeDescription?: string;

Check warning on line 54 in backend/src/modules/store/dto/store.dto.ts

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe member access .storeType on an `any` value

Check warning on line 54 in backend/src/modules/store/dto/store.dto.ts

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe member access .storeType on an `any` value

@IsString()
@IsOptional()
Expand Down Expand Up @@ -82,6 +106,23 @@
@IsOptional()
districtId?: string;

@IsString()
@IsOptional()
@IsIn([
'SHOP',
'REFUSE_SITE',
'SCHOOL',
'HOSPITAL',
'BAR_RESTAURANT',
'FUELING_STATION',
'HOTEL',
'RECREATION_PARK',
'FINANCIAL_INSTITUTION',
'RELIGIOUS',
'OTHER',
])
storeType?: StoreType;

@IsOptional()
@IsLatitude()
minLat?: `${number}`;
Expand Down
6 changes: 5 additions & 1 deletion backend/src/modules/store/entities/store.entity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { StoreType } from '../types/store.interface';
import { User } from '~/modules/user/entities/user.entity';
import { State } from '~/modules/state/entities/state.entity';
import { Phase } from '~/modules/phase/entities/phase.entity';
Expand Down Expand Up @@ -31,7 +32,10 @@ export class Store extends AbstractBaseEntity {
address: string;

@Column()
storeType: string;
storeType: StoreType;

@Column({ type: 'text', nullable: true })
storeTypeDescription?: string;

@Column({ type: 'text', nullable: true })
landmarks?: string;
Expand Down
8 changes: 5 additions & 3 deletions backend/src/modules/store/store.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ describe('StoreController', () => {
id: '1',
name: 'Test Store',
address: '123 Main St',
storeType: 'Retail',
storeType: 'SHOP' as const,
storeTypeDescription: 'Electronics store',
latitude: 123.456,
longitude: 78.901,
localGovernmentId: '1',
Expand Down Expand Up @@ -58,7 +59,8 @@ describe('StoreController', () => {
const storeDto: Omit<StoreDto, 'enumeratorId'> = {
name: 'Test Store',
address: '123 Main St',
storeType: 'Retail',
storeType: 'SHOP',
storeTypeDescription: 'Electronics store',
latitude: 123.456,
longitude: 78.901,
localGovernmentId: '1',
Expand All @@ -85,7 +87,7 @@ describe('StoreController', () => {
const storeDto: Omit<StoreDto, 'enumeratorId'> = {
name: 'Test Store',
address: '123 Main St',
storeType: 'Retail',
storeType: 'HOSPITAL',
latitude: 123.456,
longitude: 78.901,
localGovernmentId: '1',
Expand Down
Loading
Loading