Skip to content

Commit f121f1b

Browse files
committed
chore: lint issues
1 parent f298c65 commit f121f1b

File tree

11 files changed

+167
-120
lines changed

11 files changed

+167
-120
lines changed

packages/burger-api/src/blob-service.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class BlobService {
1919
BlobService.instance = new BlobService();
2020
await BlobService.instance.initialize();
2121
}
22+
2223
return BlobService.instance;
2324
}
2425

@@ -70,11 +71,11 @@ export class BlobService {
7071
const blobClient = this.containerClient.getBlobClient(firstImageName);
7172
const imageExists = await blobClient.exists();
7273

73-
if (!imageExists) {
74+
if (imageExists) {
75+
console.log('Images already exist in blob storage');
76+
} else {
7477
console.log('First image not found in blob storage. Uploading all images...');
7578
await this.uploadAllImages();
76-
} else {
77-
console.log('Images already exist in blob storage');
7879
}
7980
} catch (error) {
8081
console.error('Error checking image existence:', error);
@@ -91,16 +92,16 @@ export class BlobService {
9192

9293
try {
9394
// Path to the images directory
94-
const imagesDir = path.join(process.cwd(), 'data', 'images');
95+
const imagesDirectory = path.join(process.cwd(), 'data', 'images');
9596

9697
// Get all jpg files in the directory
97-
const imageFiles = (await fs.readdir(imagesDir)).filter((file) => file.endsWith('.jpg'));
98+
const imageFiles = (await fs.readdir(imagesDirectory)).filter((file) => file.endsWith('.jpg'));
9899

99100
console.log(`Found ${imageFiles.length} images to upload`);
100101

101102
// Upload each image
102103
for (const imageFile of imageFiles) {
103-
const filePath = path.join(imagesDir, imageFile);
104+
const filePath = path.join(imagesDirectory, imageFile);
104105
const fileContent = await fs.readFile(filePath);
105106

106107
const blockBlobClient = this.containerClient.getBlockBlobClient(imageFile);
@@ -128,7 +129,7 @@ export class BlobService {
128129
public async getBlob(blobName: string): Promise<Buffer | undefined> {
129130
// Check if we should use local fallback
130131
if (this.useLocalFallback) {
131-
return await this.getLocalFile(blobName);
132+
return this.getLocalFile(blobName);
132133
}
133134

134135
// Use Azure Blob Storage when available
@@ -223,18 +224,29 @@ export class BlobService {
223224

224225
switch (extension) {
225226
case 'jpg':
226-
case 'jpeg':
227+
case 'jpeg': {
227228
return 'image/jpeg';
228-
case 'png':
229+
}
230+
231+
case 'png': {
229232
return 'image/png';
230-
case 'gif':
233+
}
234+
235+
case 'gif': {
231236
return 'image/gif';
232-
case 'webp':
237+
}
238+
239+
case 'webp': {
233240
return 'image/webp';
234-
case 'svg':
241+
}
242+
243+
case 'svg': {
235244
return 'image/svg+xml';
236-
default:
245+
}
246+
247+
default: {
237248
return 'application/octet-stream';
249+
}
238250
}
239251
}
240252
}

packages/burger-api/src/db-service.ts

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import path from 'node:path';
2-
import { ToppingCategory } from './topping';
3-
import { Burger } from './burger';
4-
import { Topping } from './topping';
5-
import { Order, OrderStatus } from './order';
62
import { Container, CosmosClient, Database } from '@azure/cosmos';
73
import { DefaultAzureCredential } from '@azure/identity';
4+
import dotenv from 'dotenv';
85
import burgersData from '../data/burgers.json';
96
import toppingsData from '../data/toppings.json';
10-
import dotenv from 'dotenv';
7+
import { ToppingCategory, Topping } from './topping.js';
8+
import { Burger } from './burger.js';
9+
import { Order, OrderStatus } from './order.js';
1110

1211
// Env file is located in the root of the repository
1312
dotenv.config({ path: path.join(process.cwd(), '../../.env') });
1413

1514
// Helper to strip properties starting with underscore from an object
16-
function stripUnderscoreProps<T extends object>(obj: T): T {
17-
if (!obj || typeof obj !== 'object') return obj;
18-
const result: { [key: string]: any } = {};
19-
for (const key of Object.keys(obj)) {
15+
function stripUnderscoreProperties<T extends Record<string, unknown>>(object: T): T {
16+
if (!object || typeof object !== 'object') return object;
17+
const result: Record<string, any> = {};
18+
for (const key of Object.keys(object)) {
2019
if (!key.startsWith('_')) {
21-
result[key] = (obj as any)[key];
20+
result[key] = (object as any)[key];
2221
}
2322
}
23+
2424
return result as T;
2525
}
2626

@@ -33,10 +33,12 @@ function stripUserId<T extends Order | Order[] | undefined>(orderOrOrders: T): T
3333
return rest as Order;
3434
}) as T;
3535
}
36+
3637
if (orderOrOrders && typeof orderOrOrders === 'object') {
37-
const { userId, ...rest } = orderOrOrders as Order;
38+
const { userId, ...rest } = orderOrOrders;
3839
return rest as T;
3940
}
41+
4042
return orderOrOrders;
4143
}
4244

@@ -62,6 +64,7 @@ export class DbService {
6264
await DbService.instance.initializeCosmosDb();
6365
DbService.instance.initializeLocalData();
6466
}
67+
6568
return DbService.instance;
6669
}
6770

@@ -180,25 +183,27 @@ export class DbService {
180183
query: 'SELECT * FROM c',
181184
};
182185
const { resources } = await this.burgersContainer!.items.query(querySpec).fetchAll();
183-
return (resources as Burger[]).map(stripUnderscoreProps);
186+
return (resources as Burger[]).map(stripUnderscoreProperties);
184187
} catch (error) {
185188
console.error('Error fetching burgers from Cosmos DB:', error);
186189
return [...this.localBurgers];
187190
}
188191
}
192+
189193
return [...this.localBurgers];
190194
}
191195

192196
async getBurger(id: string): Promise<Burger | undefined> {
193197
if (this.isCosmosDbInitialized) {
194198
try {
195199
const { resource } = await this.burgersContainer!.item(id, id).read();
196-
return resource ? stripUnderscoreProps(resource as Burger) : undefined;
200+
return resource ? stripUnderscoreProperties(resource as Burger) : undefined;
197201
} catch (error) {
198202
console.error(`Error fetching burger ${id} from Cosmos DB:`, error);
199203
return this.localBurgers.find((burger) => burger.id === id);
200204
}
201205
}
206+
202207
return this.localBurgers.find((burger) => burger.id === id);
203208
}
204209

@@ -210,25 +215,27 @@ export class DbService {
210215
query: 'SELECT * FROM c',
211216
};
212217
const { resources } = await this.toppingsContainer!.items.query(querySpec).fetchAll();
213-
return (resources as Topping[]).map(stripUnderscoreProps);
218+
return (resources as Topping[]).map(stripUnderscoreProperties);
214219
} catch (error) {
215220
console.error('Error fetching toppings from Cosmos DB:', error);
216221
return [...this.localToppings];
217222
}
218223
}
224+
219225
return [...this.localToppings];
220226
}
221227

222228
async getTopping(id: string): Promise<Topping | undefined> {
223229
if (this.isCosmosDbInitialized) {
224230
try {
225231
const { resource } = await this.toppingsContainer!.item(id, id).read();
226-
return resource ? stripUnderscoreProps(resource as Topping) : undefined;
232+
return resource ? stripUnderscoreProperties(resource as Topping) : undefined;
227233
} catch (error) {
228234
console.error(`Error fetching topping ${id} from Cosmos DB:`, error);
229235
return this.localToppings.find((topping) => topping.id === id);
230236
}
231237
}
238+
232239
return this.localToppings.find((topping) => topping.id === id);
233240
}
234241

@@ -257,14 +264,16 @@ export class DbService {
257264
query: 'SELECT * FROM c',
258265
};
259266
}
267+
260268
const { resources } = await this.ordersContainer!.items.query(querySpec).fetchAll();
261-
return stripUserId((resources as Order[]).map(stripUnderscoreProps));
269+
return stripUserId((resources as Order[]).map(stripUnderscoreProperties));
262270
} catch (error) {
263271
console.error('Error fetching orders from Cosmos DB:', error);
264272
const orders = userId ? this.localOrders.filter((order) => order.userId === userId) : this.localOrders;
265273
return stripUserId(orders);
266274
}
267275
}
276+
268277
const orders = userId ? this.localOrders.filter((order) => order.userId === userId) : this.localOrders;
269278
return stripUserId(orders);
270279
}
@@ -275,10 +284,11 @@ export class DbService {
275284
const { resource } = await this.ordersContainer!.item(id, id).read();
276285
if (!resource) return undefined;
277286

278-
const order = stripUnderscoreProps(resource as Order);
287+
const order = stripUnderscoreProperties(resource as Order);
279288
if (userId && order.userId !== userId) {
280289
return undefined;
281290
}
291+
282292
return stripUserId(order);
283293
} catch (error) {
284294
console.error(`Error fetching order ${id} from Cosmos DB:`, error);
@@ -287,28 +297,32 @@ export class DbService {
287297
if (userId && order.userId !== userId) {
288298
return undefined;
289299
}
300+
290301
return stripUserId(order);
291302
}
292303
}
304+
293305
const order = this.localOrders.find((order) => order.id === id);
294306
if (!order) return undefined;
295307
if (userId && order.userId !== userId) {
296308
return undefined;
297309
}
310+
298311
return stripUserId(order);
299312
}
300313

301314
async createOrder(order: Order): Promise<Order> {
302315
if (this.isCosmosDbInitialized) {
303316
try {
304317
const { resource } = await this.ordersContainer!.items.create(order);
305-
return stripUserId(stripUnderscoreProps(resource as Order));
318+
return stripUserId(stripUnderscoreProperties(resource as Order));
306319
} catch (error) {
307320
console.error('Error creating order in Cosmos DB:', error);
308321
this.localOrders.push(order);
309322
return stripUserId(order);
310323
}
311324
}
325+
312326
this.localOrders.push(order);
313327
return stripUserId(order);
314328
}
@@ -325,7 +339,7 @@ export class DbService {
325339

326340
const updatedOrder = { ...existingOrder, status };
327341
const { resource } = await this.ordersContainer!.item(id, id).replace(updatedOrder);
328-
return stripUserId(stripUnderscoreProps(resource as Order));
342+
return stripUserId(stripUnderscoreProperties(resource as Order));
329343
} catch (error) {
330344
console.error(`Error updating order ${id} in Cosmos DB:`, error);
331345
const orderIndex = this.localOrders.findIndex((order) => order.id === id);
@@ -340,6 +354,7 @@ export class DbService {
340354
return stripUserId(this.localOrders[orderIndex]);
341355
}
342356
}
357+
343358
const orderIndex = this.localOrders.findIndex((order) => order.id === id);
344359
if (orderIndex === -1) return undefined;
345360

@@ -378,6 +393,7 @@ export class DbService {
378393
return true;
379394
}
380395
}
396+
381397
const orderIndex = this.localOrders.findIndex((order) => order.id === id);
382398
if (orderIndex === -1) return false;
383399

@@ -398,7 +414,7 @@ export class DbService {
398414

399415
const updatedOrder = { ...existingOrder, ...updates };
400416
const { resource } = await this.ordersContainer!.item(id, id).replace(updatedOrder);
401-
return stripUserId(stripUnderscoreProps(resource as Order));
417+
return stripUserId(stripUnderscoreProperties(resource as Order));
402418
} catch (error) {
403419
console.error(`Error updating order ${id} in Cosmos DB:`, error);
404420
const orderIndex = this.localOrders.findIndex((order) => order.id === id);
@@ -408,6 +424,7 @@ export class DbService {
408424
return stripUserId(this.localOrders[orderIndex]);
409425
}
410426
}
427+
411428
const orderIndex = this.localOrders.findIndex((order) => order.id === id);
412429
if (orderIndex === -1) return undefined;
413430

@@ -456,7 +473,7 @@ export class DbService {
456473

457474
try {
458475
const { resource } = await this.usersContainer.item(id, id).read();
459-
return !!resource;
476+
return Boolean(resource);
460477
} catch (error) {
461478
console.error('Error checking user existence:', error);
462479
return false;

packages/burger-api/src/functions/burgers-get.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { app, type HttpRequest, type InvocationContext } from '@azure/functions';
2-
import { DbService } from '../db-service';
3-
import { Burger } from '../burger';
2+
import { DbService } from '../db-service.js';
3+
import { Burger } from '../burger.js';
44

55
function transformBurgerImageUrl(burger: Burger, request: HttpRequest): Burger {
66
const url = new URL(request.url);
@@ -16,7 +16,7 @@ app.http('burgers-get', {
1616
methods: ['GET'],
1717
authLevel: 'anonymous',
1818
route: 'burgers',
19-
handler: async (request: HttpRequest, context: InvocationContext) => {
19+
async handler(request: HttpRequest, context: InvocationContext) {
2020
context.log('Processing request to get all burgers...');
2121

2222
const dataService = await DbService.getInstance();
@@ -36,8 +36,8 @@ app.http('burger-get-by-id', {
3636
methods: ['GET'],
3737
authLevel: 'anonymous',
3838
route: 'burgers/{id}',
39-
handler: async (request: HttpRequest, _context: InvocationContext) => {
40-
const id = request.params.id;
39+
async handler(request: HttpRequest, _context: InvocationContext) {
40+
const { id } = request.params;
4141
const dataService = await DbService.getInstance();
4242
const burger = await dataService.getBurger(id);
4343

packages/burger-api/src/functions/images-get.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { app, type HttpRequest, type InvocationContext } from '@azure/functions';
2-
import { BlobService } from '../blob-service';
2+
import { BlobService } from '../blob-service.js';
33

44
app.http('images-get', {
55
methods: ['GET'],
66
authLevel: 'anonymous',
77
route: 'images/{*filepath}',
8-
handler: async (request: HttpRequest, context: InvocationContext) => {
8+
async handler(request: HttpRequest, context: InvocationContext) {
99
context.log('Processing image retrieval request...');
1010
context.log('Request path:', request.params.filepath);
1111

12-
const filepath = request.params.filepath;
12+
const { filepath } = request.params;
1313

1414
if (!filepath) {
1515
return {

packages/burger-api/src/functions/openapi-get.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { app, type HttpRequest, type InvocationContext } from '@azure/functions';
21
import process from 'node:process';
32
import fs from 'node:fs/promises';
43
import path from 'node:path';
4+
import { app, type HttpRequest, type InvocationContext } from '@azure/functions';
55
import yaml from 'js-yaml';
66
import dotenv from 'dotenv';
77

@@ -12,7 +12,7 @@ app.http('openapi-get', {
1212
methods: ['GET'],
1313
authLevel: 'anonymous',
1414
route: 'openapi',
15-
handler: async (request: HttpRequest, context: InvocationContext) => {
15+
async handler(request: HttpRequest, context: InvocationContext) {
1616
context.log('Processing request to get OpenAPI specification...');
1717

1818
try {
@@ -40,8 +40,8 @@ app.http('openapi-get', {
4040
},
4141
status: 200,
4242
};
43-
} catch (err) {
44-
context.error('YAML to JSON conversion failed:', err);
43+
} catch (error) {
44+
context.error('YAML to JSON conversion failed:', error);
4545
return {
4646
jsonBody: { error: 'YAML to JSON conversion failed.' },
4747
status: 500,

0 commit comments

Comments
 (0)