Skip to content

Commit 1c4f42e

Browse files
AkatenvictorAkatenvictor
andauthored
replace types implementation (#370)
Co-authored-by: Akatenvictor <“akatenvictor@gmail.com”>
1 parent 799375d commit 1c4f42e

6 files changed

Lines changed: 241 additions & 38 deletions

File tree

src/admin/dispute/dispute.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Injectable,
44
NotFoundException,
55
} from '@nestjs/common';
6-
import { EscrowRecord, PrismaService } from '../../prisma/prisma.service';
6+
import { DisputeRecord, DisputeState, EscrowRecord, PrismaService } from '../../prisma/prisma.service';
77
import { EscrowRepository } from '../../escrow/escrow.repository';
88
import { ContractService } from '../../stellar/contract.service';
99

@@ -19,11 +19,11 @@ export class DisputeService {
1919
status?: string;
2020
page?: number;
2121
limit?: number;
22-
}): Promise<{ data: any[]; total: number; page: number; limit: number }> {
22+
}): Promise<{ data: DisputeRecord[]; total: number; page: number; limit: number }> {
2323
const page = query.page ?? 1;
2424
const limit = query.limit ?? 20;
2525
const allDisputes = await this.prisma.dispute.findMany({
26-
where: query.status ? { status: query.status as any } : undefined,
26+
where: query.status ? { status: query.status as DisputeState } : undefined,
2727
});
2828

2929
const total = allDisputes.length;

src/frontend/keyboard-a11y/focus-trap.util.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
* functional in a real browser.
77
*/
88
export interface FocusDriver {
9-
getFocusableElements: () => any[];
10-
getActiveElement: () => any;
11-
focusElement: (el: any) => void;
12-
preventDefault: (event: any) => void;
13-
addEventListener: (name: string, handler: (e: any) => void) => void;
14-
removeEventListener: (name: string, handler: (e: any) => void) => void;
9+
getFocusableElements: () => Element[];
10+
getActiveElement: () => Element | null;
11+
focusElement: (el: Element) => void;
12+
preventDefault: (event: Event) => void;
13+
addEventListener: (name: string, handler: (e: Event) => void) => void;
14+
removeEventListener: (name: string, handler: (e: Event) => void) => void;
1515
}
1616

1717
/** CSS selector matching all natively focusable / tabbable elements. */
@@ -31,8 +31,8 @@ export const FOCUSABLE_SELECTOR = [
3131
export const createDomDriver = (container: Element): FocusDriver => ({
3232
getFocusableElements: () => Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)),
3333
getActiveElement: () => document.activeElement,
34-
focusElement: (el: HTMLElement) => el.focus(),
35-
preventDefault: (e: any) => e.preventDefault(),
34+
focusElement: (el: Element) => (el as HTMLElement).focus(),
35+
preventDefault: (e: Event) => e.preventDefault(),
3636
addEventListener: (name, handler) => container.addEventListener(name, handler),
3737
removeEventListener: (name, handler) => container.removeEventListener(name, handler),
3838
});
@@ -61,31 +61,32 @@ export function createFocusTrap(
6161
onEscape?: () => void,
6262
): FocusTrap {
6363
let active = false;
64-
let previouslyFocused: any = null;
64+
let previouslyFocused: Element | null = null;
6565

66-
function handleKeyDown(event: any) {
67-
if (event.key === 'Escape') {
66+
function handleKeyDown(event: Event) {
67+
const e = event as KeyboardEvent;
68+
if (e.key === 'Escape') {
6869
deactivate();
6970
onEscape?.();
7071
return;
7172
}
7273

73-
if (event.key !== 'Tab') return;
74+
if (e.key !== 'Tab') return;
7475

7576
const focusable = driver.getFocusableElements();
7677
if (focusable.length === 0) return;
7778

7879
const first = focusable[0];
7980
const last = focusable[focusable.length - 1];
8081

81-
if (event.shiftKey) {
82+
if (e.shiftKey) {
8283
if (driver.getActiveElement() === first) {
83-
driver.preventDefault(event);
84+
driver.preventDefault(e);
8485
driver.focusElement(last);
8586
}
8687
} else {
8788
if (driver.getActiveElement() === last) {
88-
driver.preventDefault(event);
89+
driver.preventDefault(e);
8990
driver.focusElement(first);
9091
}
9192
}

src/frontend/keyboard-a11y/keyboard-a11y.util.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,13 @@ describe('validateTabOrder()', () => {
334334

335335
describe('createFocusTrap() with Mock Driver', () => {
336336
let mockDriver: FocusDriver;
337-
let focusableElements: any[];
338-
let activeElement: any;
339-
let eventListeners: Record<string, ((e: any) => void)[]>;
337+
let focusableElements: Element[];
338+
let activeElement: Element | null;
339+
let eventListeners: Record<string, ((e: Event) => void)[]>;
340340

341341
beforeEach(() => {
342-
focusableElements = [{ id: 'btn1' }, { id: 'btn2' }, { id: 'btn3' }];
343-
activeElement = { id: 'outside' };
342+
focusableElements = [{ id: 'btn1' }, { id: 'btn2' }, { id: 'btn3' }] as unknown as Element[];
343+
activeElement = { id: 'outside' } as unknown as Element;
344344
eventListeners = {};
345345

346346
mockDriver = {
@@ -379,7 +379,7 @@ describe('createFocusTrap() with Mock Driver', () => {
379379

380380
it('restores focus on deactivation', () => {
381381
const trap = createFocusTrap(mockDriver);
382-
const outside = { id: 'outside' };
382+
const outside = { id: 'outside' } as unknown as Element;
383383
activeElement = outside;
384384

385385
trap.activate();
@@ -395,7 +395,7 @@ describe('createFocusTrap() with Mock Driver', () => {
395395
activeElement = focusableElements[2]; // Last element
396396

397397
const tabHandler = eventListeners['keydown'][0];
398-
const event = { key: 'Tab', shiftKey: false };
398+
const event = { key: 'Tab', shiftKey: false } as unknown as Event;
399399

400400
tabHandler(event);
401401

@@ -409,7 +409,7 @@ describe('createFocusTrap() with Mock Driver', () => {
409409
activeElement = focusableElements[0]; // First element
410410

411411
const tabHandler = eventListeners['keydown'][0];
412-
const event = { key: 'Tab', shiftKey: true };
412+
const event = { key: 'Tab', shiftKey: true } as unknown as Event;
413413

414414
tabHandler(event);
415415

@@ -422,7 +422,7 @@ describe('createFocusTrap() with Mock Driver', () => {
422422
trap.activate();
423423

424424
const handler = eventListeners['keydown'][0];
425-
handler({ key: 'Escape' });
425+
handler({ key: 'Escape' } as unknown as Event);
426426

427427
expect(trap.isActive()).toBe(false);
428428
});
@@ -433,7 +433,7 @@ describe('createFocusTrap() with Mock Driver', () => {
433433
trap.activate();
434434

435435
const handler = eventListeners['keydown'][0];
436-
handler({ key: 'Escape' });
436+
handler({ key: 'Escape' } as unknown as Event);
437437

438438
expect(onEscape).toHaveBeenCalled();
439439
});

src/prisma/prisma.service.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface VendorTrackingSettingsRecord {
110110
requireSignature: boolean;
111111
insuranceRequired: boolean;
112112
insuranceValue: number | null;
113-
customTrackingRules: any;
113+
customTrackingRules: Record<string, unknown> | null;
114114
webhookUrl: string | null;
115115
webhookSecret: string | null;
116116
notificationChannels: string[];
@@ -247,6 +247,37 @@ type DisputeUpdateInput = Partial<
247247
>
248248
>;
249249

250+
type NotificationCreateInput = Pick<
251+
NotificationRecord,
252+
'escrowId' | 'type' | 'channel' | 'recipientAddress' | 'message'
253+
> &
254+
Partial<
255+
Pick<
256+
NotificationRecord,
257+
| 'id'
258+
| 'status'
259+
| 'retryCount'
260+
| 'sentAt'
261+
| 'failedAt'
262+
| 'lastError'
263+
| 'providerMessageId'
264+
| 'attemptCount'
265+
| 'lastResponseCode'
266+
>
267+
>;
268+
269+
type NotificationUpdateInput = Partial<
270+
Omit<NotificationRecord, 'id' | 'createdAt' | 'updatedAt'>
271+
>;
272+
273+
type VendorTrackingSettingsCreateInput = Partial<
274+
Omit<VendorTrackingSettingsRecord, 'id' | 'createdAt' | 'updatedAt'>
275+
>;
276+
277+
type VendorTrackingSettingsUpdateInput = Partial<
278+
Omit<VendorTrackingSettingsRecord, 'id' | 'vendorAddress' | 'createdAt' | 'updatedAt'>
279+
>;
280+
250281
@Injectable()
251282
export class PrismaService implements OnModuleDestroy {
252283
// databaseUrl is accepted so the module can pass the pool-tuned URL from
@@ -614,7 +645,7 @@ export class PrismaService implements OnModuleDestroy {
614645
create: ({
615646
data,
616647
}: {
617-
data: any;
648+
data: NotificationCreateInput;
618649
}): Promise<NotificationRecord> => {
619650
const now = new Date();
620651
const notification: NotificationRecord = {
@@ -639,7 +670,7 @@ export class PrismaService implements OnModuleDestroy {
639670
data,
640671
}: {
641672
where: { id: string };
642-
data: any;
673+
data: NotificationUpdateInput;
643674
}): Promise<NotificationRecord> => {
644675
const existing = this.notifications.get(where.id);
645676
if (!existing) {
@@ -985,9 +1016,9 @@ export class PrismaService implements OnModuleDestroy {
9851016
update,
9861017
}: {
9871018
where: { vendorAddress: string };
988-
create: any;
989-
update: any;
990-
}): Promise<any> => {
1019+
create: VendorTrackingSettingsCreateInput;
1020+
update: VendorTrackingSettingsUpdateInput;
1021+
}): Promise<VendorTrackingSettingsRecord> => {
9911022
const existing = this.vendorTrackingSettingsStore.get(
9921023
where.vendorAddress,
9931024
);

0 commit comments

Comments
 (0)