Skip to content

Commit 8c246b7

Browse files
committed
Type our FaceParts object
I went down the path of typing our requests as they had additional information on them, but it was simpler to just remove that param-handling and simply do it inline in the one place that it was used.
1 parent b2b95ad commit 8c246b7

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/lib/potato.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
// our libs
21
import { sumAndDiff } from './hashingFunctions';
32
import { allPaths } from './imageFiles';
43
import SlotMachine from './slotMachine';
54

5+
export interface FaceParts {
6+
color: string;
7+
eyes: string;
8+
nose: string;
9+
mouth: string;
10+
}
11+
612
const colors = [
713
'#81bef1',
814
'#ad8bf2',
@@ -23,8 +29,7 @@ class Potato {
2329
private mouthMachine = new SlotMachine(allPaths('mouth'), sumAndDiff),
2430
) {}
2531

26-
// Construct Faces Parts
27-
parts(string) {
32+
parts(string): FaceParts {
2833
return {
2934
color: this.colorMachine.pull(string),
3035
eyes: this.eyesMachine.pull(string),

src/routes/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ const sendImage = ({ stdout, response }) => {
1515
stdout.pipe(response);
1616
};
1717

18-
router.param('id', (req, res, next, id) => {
19-
const faceParts = potato.parts(id);
20-
// @ts-ignore
21-
req.faceParts = faceParts;
22-
return next();
23-
});
24-
2518
router.get('/list', (req, res) => {
2619
const response = { face: {} };
2720

@@ -41,8 +34,9 @@ router.get('/:size?/random', (req, res) => {
4134
});
4235

4336
router.get('/:size?/:id', (req, res, next) => {
44-
// @ts-ignore
45-
return combine(req.faceParts, req.params.size, (err, stdout) =>
37+
const faceParts = potato.parts(req.params.id);
38+
39+
return combine(faceParts, req.params.size, (err, stdout) =>
4640
sendImage({ stdout, response: res }),
4741
);
4842
});

0 commit comments

Comments
 (0)