Skip to content

Commit f15a295

Browse files
authored
th-170: Add customer home page (#255)
* th-170: + socket env * th-170: + method to get all active shifts with trucks * th-170: + socket events to get trucks list * th-170: + socket event listener for trucks list update * th-170: + adds the ability to display multiple markers on the map * th-170: + socket connection hook for home page * th-170: * update trucks slice to save active trucks * th-170: + home page * th-170: * .env.example on backend * th-170: * moved sendTrucksList to helpers * th-170: * fix errors * th-170: * ci fix * th-170: * update package-lock * th-170: * moved socket events to shared * th-170: * update sockets on frontend to use enums * th-170: * update sockets on backend: add room for home page * th-170: - remove client-socket-event-parameter * th-170: * disabled default ui on the map * th-170: * update scroll rule on truck list * th-170: * change truck list update interval * th-170: - removed mock data * th-170: + type for truck with location * th-170: * updated styles of tow truck card * th-170: + adds the ability to select a truck * th-170: * updated truck selectors types * th-170: * updated geolocation types * th-170: * refactoring * th-170: * renamed truck type * th-170: + add map for manufacturer names
1 parent 6a77056 commit f15a295

File tree

46 files changed

+513
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+513
-59
lines changed

backend/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ DB_DIALECT=pg
3636
DB_POOL_MIN=2
3737
DB_POOL_MAX=10
3838

39+
#
40+
# SOCKET
41+
#
42+
TRUCK_LIST_UPDATE_INTERVAL=interval_in_ms
43+
3944
#
4045
# API
4146
#

backend/src/libs/packages/config/config.package.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ class Config implements IConfig {
167167
default: null,
168168
},
169169
},
170+
SOCKET: {
171+
TRUCK_LIST_UPDATE_INTERVAL: {
172+
doc: 'Truck list update interval',
173+
format: Number,
174+
env: 'TRUCK_LIST_UPDATE_INTERVAL',
175+
default: 10_000,
176+
},
177+
},
170178
API: {
171179
GOOGLE_MAPS_API_KEY: {
172180
doc: 'Key for Google maps API',

backend/src/libs/packages/config/libs/types/environment-schema.type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type EnvironmentSchema = {
3131
SMTP_TLS: boolean;
3232
SENDGRID_SENDER_EMAIL: string;
3333
};
34+
SOCKET: {
35+
TRUCK_LIST_UPDATE_INTERVAL: number;
36+
};
3437
API: {
3538
GOOGLE_MAPS_API_KEY: string;
3639
};

backend/src/libs/packages/database/schema/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
orders,
88
ordersRelations,
99
shifts,
10+
shiftsRelations,
1011
trucks,
1112
trucksRelations,
1213
users,
@@ -20,6 +21,7 @@ const schema = {
2021
business,
2122
groups,
2223
shifts,
24+
shiftsRelations,
2325
trucks,
2426
trucksRelations,
2527
users,

backend/src/libs/packages/database/schema/tables-schema.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ const businessRelations = relations(users, ({ many }) => ({
190190
orders: many(orders),
191191
}));
192192

193+
const shiftsRelations = relations(shifts, ({ one }) => ({
194+
truck: one(trucks, {
195+
fields: [shifts.truckId],
196+
references: [trucks.id],
197+
}),
198+
}));
199+
193200
const usersTrucksRelations = relations(usersTrucks, ({ one }) => ({
194201
truck: one(trucks, {
195202
fields: [usersTrucks.truckId],
@@ -224,6 +231,7 @@ export {
224231
ordersRelations,
225232
orderStatus,
226233
shifts,
234+
shiftsRelations,
227235
trucks,
228236
trucksRelations,
229237
users,

backend/src/libs/packages/server-application/server-app.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from '~/libs/types/types.js';
2828
import { authPlugin } from '~/packages/auth/auth.js';
2929
import { filesValidationPlugin } from '~/packages/files/files.js';
30+
import { type ShiftService } from '~/packages/shifts/shift.service.js';
3031
import { userService } from '~/packages/users/users.js';
3132

3233
import { type AuthStrategyHandler } from '../controller/controller.js';
@@ -45,6 +46,7 @@ type Constructor = {
4546
logger: ILogger;
4647
database: IDatabase;
4748
apis: IServerAppApi[];
49+
shiftService: ShiftService;
4850
};
4951

5052
class ServerApp implements IServerApp {
@@ -58,11 +60,20 @@ class ServerApp implements IServerApp {
5860

5961
private app: ReturnType<typeof Fastify>;
6062

61-
public constructor({ config, logger, database, apis }: Constructor) {
63+
private shiftService: ShiftService;
64+
65+
public constructor({
66+
config,
67+
logger,
68+
database,
69+
apis,
70+
shiftService,
71+
}: Constructor) {
6272
this.config = config;
6373
this.logger = logger;
6474
this.database = database;
6575
this.apis = apis;
76+
this.shiftService = shiftService;
6677

6778
this.app = Fastify();
6879
}
@@ -267,8 +278,10 @@ class ServerApp implements IServerApp {
267278
await this.initServe();
268279

269280
socketService.initializeIo({
281+
config: this.config,
270282
app: this.app,
271283
geolocationCacheService: GeolocationCacheService.getInstance(),
284+
shiftService: this.shiftService,
272285
});
273286

274287
await this.initMiddlewares();

backend/src/libs/packages/server-application/server-application.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { authController } from '~/packages/auth/auth.js';
55
import { businessController } from '~/packages/business/business.js';
66
import { filesController } from '~/packages/files/files.js';
77
import { orderController } from '~/packages/orders/orders.js';
8-
import { shiftController } from '~/packages/shifts/shift.js';
8+
import { shiftController, shiftService } from '~/packages/shifts/shift.js';
99
import { truckController } from '~/packages/trucks/trucks.js';
1010
import { userController } from '~/packages/users/users.js';
1111

@@ -29,6 +29,7 @@ const serverApp = new ServerApp({
2929
logger,
3030
database,
3131
apis: [apiV1],
32+
shiftService,
3233
});
3334

3435
export { type ServerAppRouteParameters } from './libs/types/types.js';
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export { ServerSocketEvent } from 'shared/build/index.js';
1+
export { SocketRoom } from './socket-room.js';
2+
export { ClientSocketEvent, ServerSocketEvent } from 'shared/build/index.js';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const SocketRoom = {
2+
HOME_ROOM: 'home_room',
3+
} as const;
4+
5+
export { SocketRoom };
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
type GeolocationCacheService,
3+
type GeolocationLatLng,
4+
} from '~/libs/packages/geolocation-cache/geolocation-cache.js';
5+
import { type ShiftService } from '~/packages/shifts/shift.service.js';
6+
import { type TruckEntity } from '~/packages/trucks/libs/types/types.js';
7+
8+
type Result = TruckEntity & {
9+
location: GeolocationLatLng | undefined;
10+
};
11+
12+
const getTrucksList = async (
13+
shiftService: ShiftService,
14+
geolocationCacheService: GeolocationCacheService,
15+
): Promise<Result[]> => {
16+
const result = await shiftService.getAllStartedWithTrucks();
17+
18+
return result.map((it) => ({
19+
...it,
20+
location: geolocationCacheService.getCache(it.id),
21+
}));
22+
};
23+
24+
export { getTrucksList };

0 commit comments

Comments
 (0)