sservice area
This commit is contained in:
@@ -35,10 +35,13 @@ export class CreateRestaurantDto {
|
|||||||
@IsNumber()
|
@IsNumber()
|
||||||
longitude?: number;
|
longitude?: number;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: 5000, description: 'حوزه سرویسدهی به متر' })
|
@ApiPropertyOptional({
|
||||||
|
example: 'POLYGON((51.389 35.6892, 51.390 35.6892, 51.390 35.6902, 51.389 35.6902, 51.389 35.6892))',
|
||||||
|
description: 'محدوده سرویسدهی به صورت PostGIS Polygon (WKT format)',
|
||||||
|
})
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsString()
|
||||||
serviceArea?: number;
|
serviceArea?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' })
|
@ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -25,8 +25,11 @@ export class RestaurantSpecificationDto {
|
|||||||
@ApiPropertyOptional({ example: 51.389, description: 'Longitude' })
|
@ApiPropertyOptional({ example: 51.389, description: 'Longitude' })
|
||||||
longitude?: number;
|
longitude?: number;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: 5000, description: 'Service area in meters' })
|
@ApiPropertyOptional({
|
||||||
serviceArea?: number;
|
example: 'POLYGON((51.389 35.6892, 51.390 35.6892, 51.390 35.6902, 51.389 35.6902, 51.389 35.6892))',
|
||||||
|
description: 'Service area as PostGIS Polygon (WKT format)',
|
||||||
|
})
|
||||||
|
serviceArea?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: 2020, description: 'Established year' })
|
@ApiPropertyOptional({ example: 2020, description: 'Established year' })
|
||||||
establishedYear?: number;
|
establishedYear?: number;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Entity, Property } from '@mikro-orm/core';
|
import { Entity, Property } from '@mikro-orm/core';
|
||||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||||
|
import { PolygonType } from '../types/polygun.type';
|
||||||
|
|
||||||
@Entity({ tableName: 'restaurants' })
|
@Entity({ tableName: 'restaurants' })
|
||||||
export class Restaurant extends BaseEntity {
|
export class Restaurant extends BaseEntity {
|
||||||
@@ -20,15 +21,14 @@ export class Restaurant extends BaseEntity {
|
|||||||
menuColor?: string;
|
menuColor?: string;
|
||||||
|
|
||||||
// --- مختصات جغرافیایی ---
|
// --- مختصات جغرافیایی ---
|
||||||
@Property({ nullable: true })
|
@Property({ type: 'decimal', precision: 10, scale: 7, nullable: true })
|
||||||
latitude?: number;
|
latitude?: number;
|
||||||
|
|
||||||
@Property({ nullable: true })
|
@Property({ type: 'decimal', precision: 10, scale: 7, nullable: true })
|
||||||
longitude?: number;
|
longitude?: number;
|
||||||
|
|
||||||
// --- شعاع خدمات (مثلاً بر حسب متر یا کیلومتر) ---
|
@Property({ type: PolygonType, nullable: true })
|
||||||
@Property({ nullable: true })
|
serviceArea?: string;
|
||||||
serviceArea?: number;
|
|
||||||
|
|
||||||
// --- وضعیتها ---
|
// --- وضعیتها ---
|
||||||
@Property({ default: true })
|
@Property({ default: true })
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { Type } from '@mikro-orm/core';
|
||||||
|
import type { Platform, TransformContext } from '@mikro-orm/core';
|
||||||
|
|
||||||
|
export class PolygonType extends Type<string | null, string | null> {
|
||||||
|
getColumnType() {
|
||||||
|
return 'geometry(Polygon, 4326)';
|
||||||
|
}
|
||||||
|
|
||||||
|
convertToDatabaseValue(
|
||||||
|
value: string | null | undefined,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
_platform: Platform,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
_context?: TransformContext,
|
||||||
|
): string | null {
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Convert WKT string to PostGIS geometry
|
||||||
|
// The value should be in WKT format: "POLYGON((lon1 lat1, lon2 lat2, ...))"
|
||||||
|
// PostgreSQL will handle the conversion using ST_GeomFromText when inserting
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
convertToJSValue(
|
||||||
|
value: string | null | undefined,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
_platform: Platform,
|
||||||
|
): string | null {
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// PostgreSQL returns geometry as hex-encoded EWKB or we need to use ST_AsText
|
||||||
|
// For now, assuming the value is already in WKT format or will be converted via SQL
|
||||||
|
// If needed, you can use raw SQL in queries: SELECT ST_AsText(service_area) as service_area
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJSON(value: string | null | undefined, platform: Platform): string | null {
|
||||||
|
return this.convertToJSValue(value, platform);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,6 +113,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
slug: 'zhivan',
|
slug: 'zhivan',
|
||||||
isActive: true,
|
isActive: true,
|
||||||
phone: '09123456789',
|
phone: '09123456789',
|
||||||
|
serviceArea: 'POLYGON((51.389 35.6892, 51.390 35.6892, 51.390 35.6902, 51.389 35.6902, 51.389 35.6892))',
|
||||||
});
|
});
|
||||||
em.persist(restaurant);
|
em.persist(restaurant);
|
||||||
}
|
}
|
||||||
@@ -124,6 +125,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
slug: 'boote',
|
slug: 'boote',
|
||||||
isActive: true,
|
isActive: true,
|
||||||
phone: '09123456790',
|
phone: '09123456790',
|
||||||
|
serviceArea: 'POLYGON((51.389 35.6892, 51.390 35.6892, 51.390 35.6902, 51.389 35.6902, 51.389 35.6892))',
|
||||||
});
|
});
|
||||||
em.persist(restaurant);
|
em.persist(restaurant);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user