Skip to content

Commit 86c5607

Browse files
committed
finished project
1 parent de5dff4 commit 86c5607

File tree

17 files changed

+370
-22
lines changed

17 files changed

+370
-22
lines changed

mobile/src/pages/Detail/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface Params {
1414
interface Data {
1515
point: {
1616
image: string;
17+
image_url: string;
1718
name: string;
1819
email: string;
1920
whatsapp: string;
@@ -72,7 +73,7 @@ const Detail: React.FC = () => {
7273
<Image
7374
style={styles.pointImage}
7475
source={{
75-
uri: data.point.image,
76+
uri: data.point.image_url,
7677
}}
7778
/>
7879

mobile/src/pages/Points/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface Point {
2323
latitude: number;
2424
longitude: number;
2525
image: string;
26+
image_url:string;
2627
}
2728

2829
interface Params {
@@ -148,7 +149,7 @@ const Points: React.FC = () => {
148149
<Image
149150
style={styles.mapMarkerImage}
150151
source={{
151-
uri: point.image,
152+
uri: point.image_url,
152153
}}
153154
/>
154155
<Text style={styles.mapMarkerTitle}>{point.name}</Text>

server/package-lock.json

Lines changed: 174 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
"author": "",
1313
"license": "ISC",
1414
"dependencies": {
15+
"celebrate": "^12.1.1",
1516
"cors": "^2.8.5",
1617
"express": "^4.17.1",
1718
"knex": "^0.21.1",
19+
"multer": "^1.4.2",
1820
"sqlite3": "^4.2.0"
1921
},
2022
"devDependencies": {
2123
"@types/cors": "^2.8.6",
2224
"@types/express": "^4.17.6",
25+
"@types/hapi__joi": "^17.1.2",
26+
"@types/multer": "^1.4.3",
2327
"ts-node": "^8.10.2",
2428
"ts-node-dev": "^1.0.0-pre.44",
2529
"typescript": "^3.9.3"

server/src/config/multer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import multer from 'multer';
2+
import path from 'path';
3+
import crypto from 'crypto';
4+
5+
export default {
6+
storage: multer.diskStorage({
7+
destination: path.resolve(__dirname, '..', '..', 'uploads'),
8+
filename(request, file, callback) {
9+
const hash = crypto.randomBytes(6).toString('hex');
10+
11+
const fileName = `${hash}-${file.originalname}`;
12+
13+
callback(null, fileName);
14+
}
15+
}),
16+
}

server/src/controllers/PointsController.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class PointsController {
1717
.distinct()
1818
.select('points.*');
1919

20+
const serializedPoints = points.map(point => {
21+
return {
22+
...point,
23+
image_url: `http://192.168.15.53:3333/uploads/${point.image}`,
24+
};
25+
});
26+
2027
return response.json(points);
2128
}
2229

@@ -29,12 +36,17 @@ class PointsController {
2936
return response.status(400).json({ message: 'Point not found.'});
3037
}
3138

39+
const serializedPoint = {
40+
...point,
41+
image_url: `http://192.168.15.53:3333/uploads/${point.image}`,
42+
};
43+
3244
const items = await knex('items')
3345
.join('point_items', 'items.id', '=', 'point_items.item_id')
3446
.where('point_items.point_id', id)
3547
.select('items.title');
3648

37-
return response.json({ point, items });
49+
return response.json({ point: serializedPoint, items });
3850

3951
}
4052

@@ -53,7 +65,7 @@ class PointsController {
5365
const trx = await knex.transaction();
5466

5567
const point = {
56-
image: 'https://images.unsplash.com/photo-1556767576-5ec41e3239ea?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60',
68+
image: request.file.filename,
5769
name,
5870
email,
5971
whatsapp,
@@ -67,7 +79,10 @@ class PointsController {
6779

6880
const point_id = insertedIds[0];
6981

70-
const pointItems = items.map((item_id: number) => {
82+
const pointItems = items
83+
.split(',')
84+
.map((item: string) => Number(item.trim()))
85+
.map((item_id: number) => {
7186
return {
7287
item_id,
7388
point_id,

server/src/database/database.sqlite

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)