Skip to content

Commit 64a1274

Browse files
refactor(points): streamline point creation by consolidating value fragments and parameters
1 parent 52bb122 commit 64a1274

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

src/services/points.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ export class PointsService {
255255
const createData = changeset.create ?? [];
256256
if (createData.length > 0) {
257257
const ids = await this.generatePointIds(createData.length);
258-
const valueFragments: string[] = [];
259-
const valueParams: DatabaseSerializable[] = [];
260258
createData.forEach((data, index) => {
261259
const point: Point = {
262260
...data,
@@ -267,28 +265,26 @@ export class PointsService {
267265
createdBy: userId,
268266
};
269267
createdPoints.push(point);
270-
valueFragments.push('(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
271-
valueParams.push(
272-
point.id,
273-
airportId,
274-
point.type,
275-
point.name,
276-
JSON.stringify(point.coordinates),
277-
point.directionality ?? null,
278-
point.color ?? null,
279-
point.elevated ?? false,
280-
point.ihp ?? false,
281-
point.createdAt,
282-
point.updatedAt,
283-
point.createdBy,
284-
);
285-
});
286-
statements.push({
287-
query: `INSERT INTO points (
288-
id, airport_id, type, name, coordinates, directionality,
289-
color, elevated, ihp, created_at, updated_at, created_by
290-
) VALUES ${valueFragments.join(', ')}`,
291-
params: valueParams,
268+
statements.push({
269+
query: `INSERT INTO points (
270+
id, airport_id, type, name, coordinates, directionality,
271+
color, elevated, ihp, created_at, updated_at, created_by
272+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
273+
params: [
274+
point.id,
275+
airportId,
276+
point.type,
277+
point.name,
278+
JSON.stringify(point.coordinates),
279+
point.directionality ?? null,
280+
point.color ?? null,
281+
point.elevated ?? false,
282+
point.ihp ?? false,
283+
point.createdAt,
284+
point.updatedAt,
285+
point.createdBy,
286+
],
287+
});
292288
});
293289
}
294290

0 commit comments

Comments
 (0)