upd
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { $, Glob } from "bun";
|
||||
import path from "path";
|
||||
|
||||
// Cross-platform directory removal
|
||||
if (process.platform === "win32") {
|
||||
// await $`cmd /c "rmdir /s /q dist"`;
|
||||
} else {
|
||||
await $`rm -rf ./dist`;
|
||||
}
|
||||
|
||||
// await Bun.build({
|
||||
// entrypoints: ["./src/index.ts"],
|
||||
// env: "inline",
|
||||
// target: "bun",
|
||||
// outdir: `./dist`,
|
||||
// minify: true,
|
||||
// });
|
||||
|
||||
// Build all files in src
|
||||
for (const entrypoint of new Glob("./src/**/*.ts").scanSync()) {
|
||||
const parts = entrypoint.split(path.sep);
|
||||
const entrypointPath = path.join(...parts.slice(2, -1));
|
||||
|
||||
await Bun.build({
|
||||
entrypoints: [entrypoint],
|
||||
target: "bun",
|
||||
outdir: path.join("dist", entrypointPath),
|
||||
env: "inline",
|
||||
minify: true,
|
||||
});
|
||||
}
|
||||
Vendored
+336
File diff suppressed because one or more lines are too long
Vendored
+8
File diff suppressed because one or more lines are too long
Vendored
+2
File diff suppressed because one or more lines are too long
Vendored
+2
File diff suppressed because one or more lines are too long
Vendored
+336
File diff suppressed because one or more lines are too long
Vendored
+1
@@ -0,0 +1 @@
|
||||
// @bun
|
||||
+2
-1
@@ -3,7 +3,8 @@
|
||||
"version": "1.0.50",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "bun run --watch src/index.ts"
|
||||
"dev": "bun run --watch src/index.ts",
|
||||
"build": "bun run ./bun.build.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elysiajs/cors": "^1.2.0",
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
inArray,
|
||||
max,
|
||||
min,
|
||||
like,
|
||||
} from "drizzle-orm";
|
||||
|
||||
export const getUnitSchema = createSelectSchema(unitsTable);
|
||||
@@ -324,4 +325,93 @@ export const unitsController = new Elysia({ prefix: "/units" })
|
||||
})
|
||||
),
|
||||
}
|
||||
)
|
||||
.get(
|
||||
"/get-floors-data/:project",
|
||||
async ({ params: { project } }) => {
|
||||
try {
|
||||
// Получаем данные о номерах квартир, этажах и типах
|
||||
const unitsData = await db
|
||||
.select({
|
||||
unitNo: unitsTable.unitNo,
|
||||
floor: unitsTable.floor,
|
||||
unitType: unitsTable.unitType,
|
||||
})
|
||||
.from(unitsTable)
|
||||
.where(eq(unitsTable.project, decodeURIComponent(project)));
|
||||
|
||||
// Создаем структуру для хранения данных по этажам
|
||||
const floorMap = new Map<
|
||||
string | number,
|
||||
{
|
||||
floor: string | number;
|
||||
east: {
|
||||
types: Record<string, number>;
|
||||
totalUnits: number;
|
||||
};
|
||||
west: {
|
||||
types: Record<string, number>;
|
||||
totalUnits: number;
|
||||
};
|
||||
// totalUnits: number;
|
||||
}
|
||||
>();
|
||||
|
||||
// Обрабатываем данные квартир
|
||||
for (const { unitNo, floor, unitType } of unitsData) {
|
||||
if (!unitNo || !floor || !unitType) continue;
|
||||
|
||||
// Определяем сторону (East/West) по номеру квартиры
|
||||
const side = unitNo.toString().startsWith("W") ? "west" : "east";
|
||||
|
||||
// Инициализируем данные для этажа, если их еще нет
|
||||
if (!floorMap.has(floor)) {
|
||||
floorMap.set(floor, {
|
||||
floor,
|
||||
east: {
|
||||
types: {},
|
||||
totalUnits: 0,
|
||||
},
|
||||
west: {
|
||||
types: {},
|
||||
totalUnits: 0,
|
||||
},
|
||||
// totalUnits: 0,
|
||||
});
|
||||
}
|
||||
|
||||
const floorData = floorMap.get(floor)!;
|
||||
|
||||
// Увеличиваем счетчик для типа квартиры на соответствующей стороне
|
||||
if (side === "east") {
|
||||
floorData.east.types[unitType] =
|
||||
(floorData.east.types[unitType] || 0) + 1;
|
||||
floorData.east.totalUnits++;
|
||||
} else {
|
||||
floorData.west.types[unitType] =
|
||||
(floorData.west.types[unitType] || 0) + 1;
|
||||
floorData.west.totalUnits++;
|
||||
}
|
||||
|
||||
// Увеличиваем общий счетчик квартир на этаже
|
||||
// floorData.totalUnits++;
|
||||
}
|
||||
|
||||
// Преобразуем Map в массив и сортируем по этажам
|
||||
return Array.from(floorMap.values()).map((floorData) => ({
|
||||
floor: floorData.floor,
|
||||
east: floorData.east,
|
||||
west: floorData.west,
|
||||
// totalUnits: floorData.totalUnits,
|
||||
}));
|
||||
} catch (err) {
|
||||
console.log((err as Error).message);
|
||||
return error(500, "Internal server error");
|
||||
}
|
||||
},
|
||||
{
|
||||
params: t.Object({
|
||||
project: t.String(),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
+4
-1
@@ -1,11 +1,14 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { Elysia } from "elysia";
|
||||
import { unitsController } from "./controllers/units";
|
||||
import { cors } from "@elysiajs/cors";
|
||||
import { db } from "./db";
|
||||
import { unitsTable } from "./db/schema";
|
||||
|
||||
const app = new Elysia()
|
||||
.use(cors({ origin: "*" }))
|
||||
.use(unitsController)
|
||||
.listen(3000);
|
||||
.listen(4002);
|
||||
|
||||
console.log(
|
||||
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
|
||||
|
||||
+3
-3
@@ -25,9 +25,9 @@
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "NodeNext" /* Specify what module code is generated. */,
|
||||
"module": "ESNext" /* Specify what module code is generated. */,
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
"moduleResolution": "nodenext" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
||||
"moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
@@ -102,6 +102,6 @@
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
},
|
||||
"include": ["./drizzle.config.ts", "./env.d.ts", "src"],
|
||||
"include": ["./drizzle.config.ts", "./env.d.ts", "src", "./bun.build.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user