This commit is contained in:
Douglas Barone 2023-05-15 13:57:13 -04:00
parent a8a2a7c708
commit b019ac8dce
2 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import { Printer } from './Printer.mjs'
import fs from 'fs'
import { PrinterJSON } from './types.mjs'
export class PrinterRepository {
constructor() {
@ -13,9 +14,12 @@ export class PrinterRepository {
static instance: PrinterRepository
loadFromJSON() {
const json = JSON.parse(fs.readFileSync('./data/printers.json', 'utf8'))
const json: PrinterJSON[] = JSON.parse(
fs.readFileSync('./data/printers.json', 'utf8')
)
this.printers = json.map(
({ name, ip, model }: Printer) => new Printer(name, ip, model)
({ name, ip, model }) => new Printer(name, ip, model)
)
}

View File

@ -59,7 +59,7 @@ export type PrinterInfo = {
}
}
export type Printer = {
export type PrinterJSON = {
name: string
ip: string
model: PrinterModel