Skip to content

Commit ad61f1f

Browse files
committed
Patch
1 parent b669cc7 commit ad61f1f

32 files changed

Lines changed: 174 additions & 230 deletions

File tree

my-app/app/mirage/factories/product.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

my-app/app/mirage/models/product.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

my-app/app/mirage/routes/default.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

my-app/app/mirage/serializers/application.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

my-app/app/routes/application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class ApplicationRoute extends Route {
3131
if (isDevelopment || isProduction) {
3232
// @ts-expect-error: Incorrect type
3333
const { default: createServer } = importSync(
34-
'my-app/mirage/servers/default',
34+
'../../mirage/servers/default',
3535
);
3636

3737
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import product from './product';
1+
import { product } from './utils';
22

33
export const factories = {
44
product,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './product';
Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { faker } from '@faker-js/faker';
2+
import { Factory } from 'miragejs';
23

3-
export const categoryIds = [
4+
const categoryIds = [
45
'bacon',
56
'balloon',
67
'cake',
@@ -52,7 +53,6 @@ const imageIds: Record<CategoryId, string[]> = {
5253
'3052366',
5354
'59943',
5455
],
55-
5656
balloon: [
5757
'574282',
5858
'772478',
@@ -80,7 +80,6 @@ const imageIds: Record<CategoryId, string[]> = {
8080
'1740103',
8181
'1441024',
8282
],
83-
8483
cake: [
8584
'291528',
8685
'1055272',
@@ -110,7 +109,6 @@ const imageIds: Record<CategoryId, string[]> = {
110109
'806363',
111110
'954199',
112111
],
113-
114112
chair: [
115113
'963486',
116114
'1701100',
@@ -142,7 +140,6 @@ const imageIds: Record<CategoryId, string[]> = {
142140
'1029796',
143141
'1366875',
144142
],
145-
146143
fish: [
147144
'3606800',
148145
'842142',
@@ -205,7 +202,6 @@ const imageIds: Record<CategoryId, string[]> = {
205202
'3296544',
206203
'1199973',
207204
],
208-
209205
gloves: [
210206
'63448',
211207
'735307',
@@ -236,7 +232,6 @@ const imageIds: Record<CategoryId, string[]> = {
236232
'669578',
237233
'242829',
238234
],
239-
240235
hat: [
241236
'984619',
242237
'674268',
@@ -267,7 +262,6 @@ const imageIds: Record<CategoryId, string[]> = {
267262
'1229942',
268263
'1079783',
269264
],
270-
271265
mug: [
272266
'606542',
273267
'1207918',
@@ -298,7 +292,6 @@ const imageIds: Record<CategoryId, string[]> = {
298292
'714093',
299293
'414645',
300294
],
301-
302295
pants: [
303296
'1598507',
304297
'346749',
@@ -326,7 +319,6 @@ const imageIds: Record<CategoryId, string[]> = {
326319
'3608205',
327320
'1546694',
328321
],
329-
330322
pasta: [
331323
'1437267',
332324
'1487511',
@@ -376,7 +368,6 @@ const imageIds: Record<CategoryId, string[]> = {
376368
'688804',
377369
'725997',
378370
],
379-
380371
pizza: [
381372
'708587',
382373
'905847',
@@ -409,7 +400,6 @@ const imageIds: Record<CategoryId, string[]> = {
409400
'1653772',
410401
'2180875',
411402
],
412-
413403
sausages: [
414404
'929137',
415405
'1857732',
@@ -436,7 +426,6 @@ const imageIds: Record<CategoryId, string[]> = {
436426
'53626',
437427
'605626',
438428
],
439-
440429
shoes: [
441430
'336372',
442431
'1335463',
@@ -468,7 +457,6 @@ const imageIds: Record<CategoryId, string[]> = {
468457
'1858407',
469458
'298863',
470459
],
471-
472460
soap: [
473461
'773252',
474462
'208483',
@@ -497,7 +485,6 @@ const imageIds: Record<CategoryId, string[]> = {
497485
'3059615',
498486
'302743',
499487
],
500-
501488
towel: [
502489
'12679',
503490
'374071',
@@ -549,7 +536,7 @@ const names: Record<CategoryId, string> = {
549536
towel: 'Towel',
550537
};
551538

552-
export function getImageUrl(categoryId: CategoryId): string {
539+
function getImageUrl(categoryId: CategoryId): string {
553540
if (!(categoryId in imageIds)) {
554541
throw new Error(`Unknown category id: ${categoryId}`);
555542
}
@@ -559,6 +546,42 @@ export function getImageUrl(categoryId: CategoryId): string {
559546
return `https://images.pexels.com/photos/${imageId}/pexels-photo-${imageId}.jpeg?auto=compress&cs=tinysrgb&dpr=1&h=256`;
560547
}
561548

562-
export function getName(categoryId: CategoryId): string {
549+
function getName(categoryId: CategoryId): string {
563550
return names[categoryId];
564551
}
552+
553+
export const product = Factory.extend({
554+
categoryId() {
555+
return faker.helpers.arrayElement(categoryIds);
556+
},
557+
558+
description() {
559+
return faker.lorem.sentences();
560+
},
561+
562+
imageUrl() {
563+
// @ts-expect-error: Incorrect type
564+
return getImageUrl(this.categoryId);
565+
},
566+
567+
name() {
568+
// @ts-expect-error: Incorrect type
569+
return `${faker.commerce.productMaterial()} ${getName(this.categoryId)}`;
570+
},
571+
572+
price() {
573+
return faker.number.float({ max: 100, min: 5, multipleOf: 1 });
574+
},
575+
576+
rating() {
577+
return faker.number.float({ max: 5, min: 1, multipleOf: 0.5 });
578+
},
579+
580+
seller() {
581+
return faker.company.name();
582+
},
583+
584+
shortDescription() {
585+
return faker.company.catchPhrase();
586+
},
587+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import product from './product';
1+
import { product } from './utils';
22

33
export const models = {
44
product,

0 commit comments

Comments
 (0)