Files
tehran_taj/apps/api/src/modules/admin-cities/admin-cities.controller.ts
T

32 lines
1.0 KiB
TypeScript
Raw Normal View History

import { Controller, HttpCode, Post } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
/**
* Legacy `POST cities/list` — the city lookup the table filters use.
* Returns `{ rows }`, matching what the users store's setCities() reads.
*
* Deliberately NOT permission-gated: legacy called this from table models at
* module load, before any rid check, and it exposes nothing sensitive.
*/
@Controller('admin/cities')
export class AdminCitiesController {
constructor(private readonly prisma: PrismaService) {}
@Post('list')
@HttpCode(200)
async list() {
const cities = await this.prisma.city.findMany({ orderBy: { name: 'asc' } });
// legacy shape: the cities row — { id, title, parent, percent, percent_aux }.
// `parent` lets the admin pickers draw legacy's tree (PERS-02).
return {
rows: cities.map((c) => ({
id: c.id,
title: c.name,
parent: c.parentId,
percent: c.percent,
percent_aux: c.percentAux,
})),
};
}
}