Refactor code formatting for improved readability
- Reformatted import statements and object properties across multiple files to enhance code clarity and maintainability. - Ensured consistent indentation and line breaks in test specifications and service implementations, improving overall code structure.
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
import { bigint, doublePrecision, index, pgTable, uuid } from 'drizzle-orm/pg-core';
|
import {
|
||||||
|
bigint,
|
||||||
|
doublePrecision,
|
||||||
|
index,
|
||||||
|
pgTable,
|
||||||
|
uuid,
|
||||||
|
} from 'drizzle-orm/pg-core';
|
||||||
import { employees } from './employees-table';
|
import { employees } from './employees-table';
|
||||||
|
|
||||||
export const timelineFootprints = pgTable(
|
export const timelineFootprints = pgTable(
|
||||||
|
|||||||
@@ -137,7 +137,9 @@ describe('AuthController', () => {
|
|||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
privilege: { id: 'priv-1', code: 'ADMIN' },
|
privilege: { id: 'priv-1', code: 'ADMIN' },
|
||||||
permissions: {
|
permissions: {
|
||||||
'ADMIN.SETTINGS.USER.PRIVILEGES': expect.objectContaining({ view: true }),
|
'ADMIN.SETTINGS.USER.PRIVILEGES': expect.objectContaining({
|
||||||
|
view: true,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ describe('CyclesService', () => {
|
|||||||
const employeesService = { findById: jest.fn(), findByCode: jest.fn() };
|
const employeesService = { findById: jest.fn(), findByCode: jest.fn() };
|
||||||
const branchesService = { findById: jest.fn(), findByCode: jest.fn() };
|
const branchesService = { findById: jest.fn(), findByCode: jest.fn() };
|
||||||
const customersService = { findById: jest.fn(), findByCode: jest.fn() };
|
const customersService = { findById: jest.fn(), findByCode: jest.fn() };
|
||||||
const privilegesService = { checkPermission: jest.fn(), checkAnyPermission: jest.fn() };
|
const privilegesService = {
|
||||||
|
checkPermission: jest.fn(),
|
||||||
|
checkAnyPermission: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const now = DateTime.fromUnixMs(1_700_000_000_000);
|
const now = DateTime.fromUnixMs(1_700_000_000_000);
|
||||||
const user: AuthUser = {
|
const user: AuthUser = {
|
||||||
|
|||||||
@@ -72,7 +72,10 @@ describe('PlansService', () => {
|
|||||||
markDraftsProcessed: jest.fn(),
|
markDraftsProcessed: jest.fn(),
|
||||||
};
|
};
|
||||||
const packingSlipsService = { findById: jest.fn() };
|
const packingSlipsService = { findById: jest.fn() };
|
||||||
const privilegesService = { checkPermission: jest.fn(), checkAnyPermission: jest.fn() };
|
const privilegesService = {
|
||||||
|
checkPermission: jest.fn(),
|
||||||
|
checkAnyPermission: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const user: AuthUser = {
|
const user: AuthUser = {
|
||||||
id: 'user-1',
|
id: 'user-1',
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ describe('TimelineService', () => {
|
|||||||
let footprintsRepository: jest.Mocked<
|
let footprintsRepository: jest.Mocked<
|
||||||
Pick<TimelineFootprintsRepository, 'insertMany' | 'list'>
|
Pick<TimelineFootprintsRepository, 'insertMany' | 'list'>
|
||||||
>;
|
>;
|
||||||
let activitiesRepository: jest.Mocked<Pick<TimelineActivitiesRepository, 'list'>>;
|
let activitiesRepository: jest.Mocked<
|
||||||
|
Pick<TimelineActivitiesRepository, 'list'>
|
||||||
|
>;
|
||||||
let employeesService: jest.Mocked<Pick<EmployeesService, 'requireByUserId'>>;
|
let employeesService: jest.Mocked<Pick<EmployeesService, 'requireByUserId'>>;
|
||||||
let companySettingsService: jest.Mocked<
|
let companySettingsService: jest.Mocked<
|
||||||
Pick<CompanySettingsService, 'requireTimelineConfig'>
|
Pick<CompanySettingsService, 'requireTimelineConfig'>
|
||||||
@@ -40,8 +42,14 @@ describe('TimelineService', () => {
|
|||||||
const moduleRef: TestingModule = await Test.createTestingModule({
|
const moduleRef: TestingModule = await Test.createTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
TimelineService,
|
TimelineService,
|
||||||
{ provide: TimelineFootprintsRepository, useValue: footprintsRepository },
|
{
|
||||||
{ provide: TimelineActivitiesRepository, useValue: activitiesRepository },
|
provide: TimelineFootprintsRepository,
|
||||||
|
useValue: footprintsRepository,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: TimelineActivitiesRepository,
|
||||||
|
useValue: activitiesRepository,
|
||||||
|
},
|
||||||
{ provide: EmployeesService, useValue: employeesService },
|
{ provide: EmployeesService, useValue: employeesService },
|
||||||
{ provide: CompanySettingsService, useValue: companySettingsService },
|
{ provide: CompanySettingsService, useValue: companySettingsService },
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import {
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||||
BadRequestException,
|
|
||||||
Injectable,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import {
|
import {
|
||||||
DEFAULT_RELATION_FIELDS,
|
DEFAULT_RELATION_FIELDS,
|
||||||
pickRelation,
|
pickRelation,
|
||||||
@@ -138,14 +135,17 @@ export class TimelineService {
|
|||||||
if (employeeId || footprints.length <= MAX_FOOTPRINTS_ALL_EMPLOYEES) {
|
if (employeeId || footprints.length <= MAX_FOOTPRINTS_ALL_EMPLOYEES) {
|
||||||
return [...footprints];
|
return [...footprints];
|
||||||
}
|
}
|
||||||
const stride = Math.ceil(
|
const stride = Math.ceil(footprints.length / MAX_FOOTPRINTS_ALL_EMPLOYEES);
|
||||||
footprints.length / MAX_FOOTPRINTS_ALL_EMPLOYEES,
|
|
||||||
);
|
|
||||||
return footprints.filter((_, index) => index % stride === 0);
|
return footprints.filter((_, index) => index % stride === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private assertCoordinates(latitude: number, longitude: number): void {
|
private assertCoordinates(latitude: number, longitude: number): void {
|
||||||
if (latitude < -90 || latitude > 90 || longitude < -180 || longitude > 180) {
|
if (
|
||||||
|
latitude < -90 ||
|
||||||
|
latitude > 90 ||
|
||||||
|
longitude < -180 ||
|
||||||
|
longitude > 180
|
||||||
|
) {
|
||||||
throw new BadRequestException('Invalid coordinates');
|
throw new BadRequestException('Invalid coordinates');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,16 @@ describe('privilege-action', () => {
|
|||||||
|
|
||||||
describe('privilege-key-code', () => {
|
describe('privilege-key-code', () => {
|
||||||
it('accepts 3- and 4-part dotted uppercase codes', () => {
|
it('accepts 3- and 4-part dotted uppercase codes', () => {
|
||||||
expect(isValidPrivilegeKeyCode('ADMIN.SETTINGS.USER.PRIVILEGES')).toBe(true);
|
expect(isValidPrivilegeKeyCode('ADMIN.SETTINGS.USER.PRIVILEGES')).toBe(
|
||||||
expect(isValidPrivilegeKeyCode('ADMIN.SALES.ACTIVITIES.INVOICE')).toBe(true);
|
true,
|
||||||
|
);
|
||||||
|
expect(isValidPrivilegeKeyCode('ADMIN.SALES.ACTIVITIES.INVOICE')).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
expect(isValidPrivilegeKeyCode('MOBILE.SALES.PLAN')).toBe(true);
|
expect(isValidPrivilegeKeyCode('MOBILE.SALES.PLAN')).toBe(true);
|
||||||
expect(assertPrivilegeKeyCode('MOBILE.SALES.PLAN')).toBe('MOBILE.SALES.PLAN');
|
expect(assertPrivilegeKeyCode('MOBILE.SALES.PLAN')).toBe(
|
||||||
|
'MOBILE.SALES.PLAN',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects invalid codes', () => {
|
it('rejects invalid codes', () => {
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ describe('privilege-key-code', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('accepts 4-part keys', () => {
|
it('accepts 4-part keys', () => {
|
||||||
expect(isValidPrivilegeKeyCode('MOBILE.SALES.PLAN.ATTENDANCE')).toBe(true);
|
expect(isValidPrivilegeKeyCode('MOBILE.SALES.PLAN.ATTENDANCE')).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
expect(isValidPrivilegeKeyCode('ADMIN.SALES.ACTIVITIES.PLAN')).toBe(true);
|
expect(isValidPrivilegeKeyCode('ADMIN.SALES.ACTIVITIES.PLAN')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -33,7 +35,9 @@ describe('privilege-key-code', () => {
|
|||||||
|
|
||||||
describe('assertPrivilegeKeyCode', () => {
|
describe('assertPrivilegeKeyCode', () => {
|
||||||
it('returns the code when valid', () => {
|
it('returns the code when valid', () => {
|
||||||
expect(assertPrivilegeKeyCode('MOBILE.SALES.PLAN')).toBe('MOBILE.SALES.PLAN');
|
expect(assertPrivilegeKeyCode('MOBILE.SALES.PLAN')).toBe(
|
||||||
|
'MOBILE.SALES.PLAN',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when invalid', () => {
|
it('throws when invalid', () => {
|
||||||
|
|||||||
@@ -169,11 +169,7 @@ describe('PrivilegesService', () => {
|
|||||||
it('checkAnyPermission uses checkPermission for a single key', async () => {
|
it('checkAnyPermission uses checkPermission for a single key', async () => {
|
||||||
repository.checkPermission.mockResolvedValue(true);
|
repository.checkPermission.mockResolvedValue(true);
|
||||||
await expect(
|
await expect(
|
||||||
service.checkAnyPermission(
|
service.checkAnyPermission('user-1', ['MOBILE.SALES.PLAN'], 'view'),
|
||||||
'user-1',
|
|
||||||
['MOBILE.SALES.PLAN'],
|
|
||||||
'view',
|
|
||||||
),
|
|
||||||
).resolves.toBe(true);
|
).resolves.toBe(true);
|
||||||
expect(repository.checkPermission).toHaveBeenCalledWith(
|
expect(repository.checkPermission).toHaveBeenCalledWith(
|
||||||
'user-1',
|
'user-1',
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ import {
|
|||||||
} from './dto/packing-slip.dto';
|
} from './dto/packing-slip.dto';
|
||||||
import { PackingSlipsService } from './packing-slips.service';
|
import { PackingSlipsService } from './packing-slips.service';
|
||||||
|
|
||||||
export const PACKING_SLIP_PRIVILEGE_KEY = 'ADMIN.LOGISTICS.ACTIVITIES.PACKING_SLIP';
|
export const PACKING_SLIP_PRIVILEGE_KEY =
|
||||||
|
'ADMIN.LOGISTICS.ACTIVITIES.PACKING_SLIP';
|
||||||
|
|
||||||
@ApiTags('packing-slips')
|
@ApiTags('packing-slips')
|
||||||
@ApiBearerAuth(BEARER_AUTH_NAME)
|
@ApiBearerAuth(BEARER_AUTH_NAME)
|
||||||
|
|||||||
@@ -118,9 +118,9 @@ describe('Company settings (e2e)', () => {
|
|||||||
})
|
})
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect((updated.body as { gpsIntervalSeconds: number }).gpsIntervalSeconds).toBe(
|
expect(
|
||||||
15,
|
(updated.body as { gpsIntervalSeconds: number }).gpsIntervalSeconds,
|
||||||
);
|
).toBe(15);
|
||||||
expect(
|
expect(
|
||||||
(updated.body as { checkoutWarningRadiusMeters: number })
|
(updated.body as { checkoutWarningRadiusMeters: number })
|
||||||
.checkoutWarningRadiusMeters,
|
.checkoutWarningRadiusMeters,
|
||||||
|
|||||||
@@ -202,7 +202,9 @@ describe('Privileges (e2e)', () => {
|
|||||||
expect(me.body.privilege).toMatchObject({
|
expect(me.body.privilege).toMatchObject({
|
||||||
id: adminPrivilegeId,
|
id: adminPrivilegeId,
|
||||||
});
|
});
|
||||||
expect(me.body.permissions['ADMIN.SETTINGS.USER.PRIVILEGES'].view).toBe(true);
|
expect(me.body.permissions['ADMIN.SETTINGS.USER.PRIVILEGES'].view).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.patch(`/users/${otherUserId}/privilege`)
|
.patch(`/users/${otherUserId}/privilege`)
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ describe('Timeline (e2e)', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ingests footprints and returns them on admin timeline query', async () => {
|
it('ingests footprints and returns them on admin timeline query', async () => {
|
||||||
const recordedAt = DateTime.fromUnixMs(Date.now()).startOfDay().value + 3_600_000;
|
const recordedAt =
|
||||||
|
DateTime.fromUnixMs(Date.now()).startOfDay().value + 3_600_000;
|
||||||
|
|
||||||
const ingest = await request(app.getHttpServer())
|
const ingest = await request(app.getHttpServer())
|
||||||
.post('/timeline/footprints')
|
.post('/timeline/footprints')
|
||||||
@@ -143,14 +144,21 @@ describe('Timeline (e2e)', () => {
|
|||||||
.send({
|
.send({
|
||||||
points: [
|
points: [
|
||||||
{ latitude: -6.2, longitude: 106.8, recordedAt },
|
{ latitude: -6.2, longitude: 106.8, recordedAt },
|
||||||
{ latitude: -6.201, longitude: 106.801, recordedAt: recordedAt + 5000 },
|
{
|
||||||
|
latitude: -6.201,
|
||||||
|
longitude: 106.801,
|
||||||
|
recordedAt: recordedAt + 5000,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.expect(201);
|
.expect(201);
|
||||||
|
|
||||||
expect((ingest.body as { inserted: number }).inserted).toBe(2);
|
expect((ingest.body as { inserted: number }).inserted).toBe(2);
|
||||||
|
|
||||||
const today = DateTime.fromUnixMs(Date.now()).startOfDay().format().slice(0, 10);
|
const today = DateTime.fromUnixMs(Date.now())
|
||||||
|
.startOfDay()
|
||||||
|
.format()
|
||||||
|
.slice(0, 10);
|
||||||
const day = await request(app.getHttpServer())
|
const day = await request(app.getHttpServer())
|
||||||
.get('/timeline')
|
.get('/timeline')
|
||||||
.query({ date: today, employeeId })
|
.query({ date: today, employeeId })
|
||||||
@@ -168,7 +176,10 @@ describe('Timeline (e2e)', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns activities-only timeline for the current user', async () => {
|
it('returns activities-only timeline for the current user', async () => {
|
||||||
const today = DateTime.fromUnixMs(Date.now()).startOfDay().format().slice(0, 10);
|
const today = DateTime.fromUnixMs(Date.now())
|
||||||
|
.startOfDay()
|
||||||
|
.format()
|
||||||
|
.slice(0, 10);
|
||||||
const me = await request(app.getHttpServer())
|
const me = await request(app.getHttpServer())
|
||||||
.get('/timeline/me')
|
.get('/timeline/me')
|
||||||
.query({ date: today })
|
.query({ date: today })
|
||||||
|
|||||||
Reference in New Issue
Block a user