mirror of
https://gitlab.com/mobicoop/v3/service/territory.git
synced 2026-03-22 16:55:50 +00:00
find territories for a point
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaClientKnownRequestError } from '@prisma/client/runtime';
|
||||
import { Point } from '../../domain/point.type';
|
||||
import { DatabaseException } from '../../exceptions/database.exception';
|
||||
import { ICollection } from '../../interfaces/collection.interface';
|
||||
import { IRepository } from '../../interfaces/repository.interface';
|
||||
@@ -182,4 +183,13 @@ export abstract class PrismaRepository<T> implements IRepository<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async findForPoint(point: Point): Promise<ICollection<T>> {
|
||||
const strPoint = `SELECT uuid, name FROM ${this._model} WHERE ST_Intersects('POINT(${point.lon} ${point.lat})',shape) = true`;
|
||||
const territories: Array<T> = await this._prisma.$queryRawUnsafe(strPoint);
|
||||
return Promise.resolve({
|
||||
data: territories,
|
||||
total: territories.length,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
4
src/modules/database/src/domain/point.type.ts
Normal file
4
src/modules/database/src/domain/point.type.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export type Point = {
|
||||
lon: number;
|
||||
lat: number;
|
||||
};
|
||||
Reference in New Issue
Block a user