sservice area
This commit is contained in:
@@ -35,10 +35,13 @@ export class CreateRestaurantDto {
|
||||
@IsNumber()
|
||||
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()
|
||||
@IsNumber()
|
||||
serviceArea?: number;
|
||||
@IsString()
|
||||
serviceArea?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' })
|
||||
@IsOptional()
|
||||
|
||||
@@ -25,8 +25,11 @@ export class RestaurantSpecificationDto {
|
||||
@ApiPropertyOptional({ example: 51.389, description: 'Longitude' })
|
||||
longitude?: number;
|
||||
|
||||
@ApiPropertyOptional({ example: 5000, description: 'Service area in meters' })
|
||||
serviceArea?: number;
|
||||
@ApiPropertyOptional({
|
||||
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' })
|
||||
establishedYear?: number;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Entity, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { PolygonType } from '../types/polygun.type';
|
||||
|
||||
@Entity({ tableName: 'restaurants' })
|
||||
export class Restaurant extends BaseEntity {
|
||||
@@ -20,15 +21,14 @@ export class Restaurant extends BaseEntity {
|
||||
menuColor?: string;
|
||||
|
||||
// --- مختصات جغرافیایی ---
|
||||
@Property({ nullable: true })
|
||||
@Property({ type: 'decimal', precision: 10, scale: 7, nullable: true })
|
||||
latitude?: number;
|
||||
|
||||
@Property({ nullable: true })
|
||||
@Property({ type: 'decimal', precision: 10, scale: 7, nullable: true })
|
||||
longitude?: number;
|
||||
|
||||
// --- شعاع خدمات (مثلاً بر حسب متر یا کیلومتر) ---
|
||||
@Property({ nullable: true })
|
||||
serviceArea?: number;
|
||||
@Property({ type: PolygonType, nullable: true })
|
||||
serviceArea?: string;
|
||||
|
||||
// --- وضعیتها ---
|
||||
@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',
|
||||
isActive: true,
|
||||
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);
|
||||
}
|
||||
@@ -124,6 +125,7 @@ export class DatabaseSeeder extends Seeder {
|
||||
slug: 'boote',
|
||||
isActive: true,
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user