Skip to content

Commit 4964d9d

Browse files
authored
Merge pull request #46 from icefoganalytics/caleb/dev
Fixs and updates to photos
2 parents 88ad780 + 435e818 commit 4964d9d

File tree

16 files changed

+1233
-617
lines changed

16 files changed

+1233
-617
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ db/place_data.sql
116116

117117
# Other
118118
.DS_Store
119+
notes.md

api/controllers/photos.ts

Lines changed: 100 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import express, { Request, Response } from "express";
1+
import express, { Request, Response } from 'express';
22
import { RequiresAuthentication } from '../middleware';
3-
import _ from "lodash";
4-
import { createThumbnail } from "../utils/image";
5-
import multer from "multer";
3+
import _ from 'lodash';
4+
import { createThumbnail } from '../utils/image';
5+
import multer from 'multer';
66

77
var router = express.Router();
88

@@ -28,11 +28,7 @@ router.get('/', RequiresAuthentication, async (req: Request, res: Response) => {
2828
.count('RowId', { as: 'count' });
2929

3030
photos = await db
31-
.column(
32-
'PH.*',
33-
{ CommunityName: 'CO.Name' },
34-
{ PlaceName: 'PL.PrimaryName' }
35-
)
31+
.column('PH.*', { CommunityName: 'CO.Name' }, { PlaceName: 'PL.PrimaryName' })
3632
.select()
3733
.from('dbo.photo as PH')
3834
.join('dbo.Community as CO', 'PH.CommunityId', '=', 'CO.Id')
@@ -47,17 +43,10 @@ router.get('/', RequiresAuthentication, async (req: Request, res: Response) => {
4743
.limit(limit)
4844
.offset(offset);
4945
} else {
50-
counter = await db
51-
.from('dbo.photo')
52-
.count('RowId', { as: 'count' })
53-
.first();
46+
counter = await db.from('dbo.photo').count('RowId', { as: 'count' }).first();
5447

5548
photos = await db
56-
.column(
57-
'PH.*',
58-
{ CommunityName: 'CO.Name' },
59-
{ PlaceName: 'PL.PrimaryName' }
60-
)
49+
.column('PH.*', { CommunityName: 'CO.Name' }, { PlaceName: 'PL.PrimaryName' })
6150
.select()
6251
.from('dbo.photo as PH')
6352
.join('dbo.Community as CO', 'PH.CommunityId', '=', 'CO.Id')
@@ -70,39 +59,62 @@ router.get('/', RequiresAuthentication, async (req: Request, res: Response) => {
7059
res.status(200).send({ count: counter, body: photos });
7160
});
7261

73-
//LINK BOAT PHOTOS
74-
router.post(
75-
'/boat/link/:BoatId',
76-
RequiresAuthentication,
77-
async (req: Request, res: Response) => {
62+
//LINK PLACE (aka site) PHOTOS
63+
router.post('/place/link/:PlaceId', RequiresAuthentication, async (req: Request, res: Response) => {
64+
try {
7865
const db = req.app.get('db');
7966

80-
const { BoatId } = req.params;
67+
const { PlaceId } = req.params;
8168
const { linkPhotos } = req.body;
8269

83-
let currentPhotos = await db
84-
.select('Photo_RowID')
85-
.from('boat.Photo')
86-
.where('BoatId', BoatId);
87-
let filteredLinkPhotos = _.difference(
70+
const currentPhotosForPlace = await db
71+
.select('PhotoId')
72+
.from('dbo.Photo')
73+
.where('PlaceId', PlaceId);
74+
75+
const filteredLinkPhotos = _.difference(
8876
linkPhotos,
89-
currentPhotos.map((x: any) => {
90-
return x.Photo_RowID;
77+
currentPhotosForPlace.map((x: any) => {
78+
return x.PhotoId;
9179
})
9280
);
9381

9482
for (const rowId of filteredLinkPhotos) {
95-
await db
96-
.insert({ BoatId, Photo_RowID: rowId })
97-
.into('boat.photo')
98-
.returning('*')
99-
.then((rows: any) => {
100-
return rows;
101-
});
83+
console.log('LINKING', { rowId });
10284
}
10385
res.status(200).send({ message: 'Successfully linked the photos' });
86+
} catch (error) {
87+
console.error(error);
88+
res.status(500).send({ message: 'Failed to link photos' });
10489
}
105-
);
90+
});
91+
92+
//LINK BOAT PHOTOS
93+
router.post('/boat/link/:BoatId', RequiresAuthentication, async (req: Request, res: Response) => {
94+
const db = req.app.get('db');
95+
96+
const { BoatId } = req.params;
97+
const { linkPhotos } = req.body;
98+
99+
const currentPhotos = await db.select('Photo_RowID').from('boat.Photo').where('BoatId', BoatId);
100+
const filteredLinkPhotos = _.difference(
101+
linkPhotos,
102+
currentPhotos.map((x: any) => {
103+
return x.Photo_RowID;
104+
})
105+
);
106+
107+
for (const rowId of filteredLinkPhotos) {
108+
await db
109+
.insert({ BoatId, Photo_RowID: rowId })
110+
.into('boat.photo')
111+
.returning('*')
112+
.then((rows: any) => {
113+
return rows;
114+
});
115+
}
116+
res.status(200).send({ message: 'Successfully linked the photos' });
117+
});
106118

107119
//LINK PERSON PHOTOS
108120
router.post(
@@ -114,11 +126,11 @@ router.post(
114126
const { PersonID } = req.params;
115127
const { linkPhotos } = req.body;
116128

117-
let currentPhotos = await db
129+
const currentPhotos = await db
118130
.select('PhotoID')
119131
.from('Person.Photo')
120132
.where('PersonID', PersonID);
121-
let filteredLinkPhotos = _.difference(
133+
const filteredLinkPhotos = _.difference(
122134
linkPhotos,
123135
currentPhotos.map((x: any) => {
124136
return x.Photo_RowID;
@@ -147,11 +159,11 @@ router.post(
147159

148160
const { AirCrashId } = req.params;
149161
const { linkPhotos } = req.body;
150-
let currentPhotos = await db
162+
const currentPhotos = await db
151163
.select('Photo_RowID')
152164
.from('AirCrash.Photo')
153165
.where('YACSINumber', AirCrashId);
154-
let filteredLinkPhotos = _.difference(
166+
const filteredLinkPhotos = _.difference(
155167
linkPhotos,
156168
currentPhotos.map((x: any) => {
157169
return x.Photo_RowID;
@@ -172,72 +184,60 @@ router.post(
172184
);
173185

174186
//GET BOAT PHOTOS
175-
router.get(
176-
'/boat/:boatId',
177-
RequiresAuthentication,
178-
async (req: Request, res: Response) => {
179-
const { boatId } = req.params;
187+
router.get('/boat/:boatId', RequiresAuthentication, async (req: Request, res: Response) => {
188+
const { boatId } = req.params;
180189

181-
const db = req.app.get('db');
182-
const { page = 0, limit = 10 } = req.query;
183-
const offset = Number(page) * Number(limit) || 0;
184-
185-
const photos = await db
186-
.select('*')
187-
.from('boat.photo as BP')
188-
.join('dbo.photo', 'BP.Photo_RowID', '=', 'dbo.photo.RowID')
189-
.where('BP.boatid', boatId)
190-
.limit(limit)
191-
.offset(offset);
190+
const db = req.app.get('db');
191+
const { page = 0, limit = 10 } = req.query;
192+
const offset = Number(page) * Number(limit) || 0;
192193

193-
res.status(200).send(photos);
194-
}
195-
);
194+
const photos = await db
195+
.select('*')
196+
.from('boat.photo as BP')
197+
.join('dbo.photo', 'BP.Photo_RowID', '=', 'dbo.photo.RowID')
198+
.where('BP.boatid', boatId)
199+
.limit(limit)
200+
.offset(offset);
201+
202+
res.status(200).send(photos);
203+
});
196204

197205
// GET AIRCRASH PHOTOS
198-
router.get(
199-
'/aircrash/:aircrashId',
200-
RequiresAuthentication,
201-
async (req: Request, res: Response) => {
202-
const { aircrashId } = req.params;
206+
router.get('/aircrash/:aircrashId', RequiresAuthentication, async (req: Request, res: Response) => {
207+
const { aircrashId } = req.params;
203208

204-
const db = req.app.get('db');
205-
const { page = 0, limit = 10 } = req.query;
206-
const offset = Number(page) * Number(limit) || 0;
207-
208-
const photos = await db
209-
.select('*')
210-
.from('AirCrash.Photo as AP')
211-
.join('dbo.photo', 'AP.Photo_RowID', '=', 'dbo.photo.RowID')
212-
.where('AP.YACSINumber', aircrashId)
213-
.limit(limit)
214-
.offset(offset);
209+
const db = req.app.get('db');
210+
const { page = 0, limit = 10 } = req.query;
211+
const offset = Number(page) * Number(limit) || 0;
215212

216-
res.status(200).send(photos);
217-
}
218-
);
213+
const photos = await db
214+
.select('*')
215+
.from('AirCrash.Photo as AP')
216+
.join('dbo.photo', 'AP.Photo_RowID', '=', 'dbo.photo.RowID')
217+
.where('AP.YACSINumber', aircrashId)
218+
.limit(limit)
219+
.offset(offset);
220+
221+
res.status(200).send(photos);
222+
});
219223

220224
//GET PERSON PHOTOS
221-
router.get(
222-
'/people/:PersonID',
223-
RequiresAuthentication,
224-
async (req: Request, res: Response) => {
225-
const { PersonID } = req.params;
225+
router.get('/people/:PersonID', RequiresAuthentication, async (req: Request, res: Response) => {
226+
const { PersonID } = req.params;
226227

227-
const db = req.app.get('db');
228-
const { page = 0, limit = 10 } = req.query;
229-
const offset = Number(page) * Number(limit) || 0;
230-
231-
const photos = await db
232-
.select('*')
233-
.from('Person.Photo as PP')
234-
.join('dbo.photo', 'PP.PhotoID', '=', 'dbo.photo.RowID')
235-
.where('PP.PersonID', PersonID)
236-
.limit(limit)
237-
.offset(offset);
238-
res.status(200).send(photos);
239-
}
240-
);
228+
const db = req.app.get('db');
229+
const { page = 0, limit = 10 } = req.query;
230+
const offset = Number(page) * Number(limit) || 0;
231+
232+
const photos = await db
233+
.select('*')
234+
.from('Person.Photo as PP')
235+
.join('dbo.photo', 'PP.PhotoID', '=', 'dbo.photo.RowID')
236+
.where('PP.PersonID', PersonID)
237+
.limit(limit)
238+
.offset(offset);
239+
res.status(200).send(photos);
240+
});
241241

242242
// ADD NEW BOAT PHOTO
243243
router.post(
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { type Knex } from 'knex';
2+
3+
export async function up(knex: Knex): Promise<void> {
4+
// Best guess based on existing code as I don't have a copy of the database
5+
await knex.schema.withSchema('dbo').alterTable('Photo', (table) => {
6+
table.integer('Id').nullable();
7+
table.string('NTSMapNumber', 20).nullable();
8+
table.dateTime('DateCreated').nullable();
9+
table.string('YHSIRecord', 20).nullable();
10+
table.string('BordenRecord', 20).nullable();
11+
table.string('PaleoRecord', 20).nullable();
12+
table.string('ArchivalRecord', 20).nullable();
13+
table.boolean('IsOtherRecord').notNullable();
14+
table.integer('OriginalMediaId').nullable();
15+
table.string('OriginalRecord', 256).nullable();
16+
table.integer('MediaStorage').notNullable();
17+
table.text('Comments').nullable();
18+
table.integer('Copyright').notNullable();
19+
table.string('CreditLine', 256).nullable();
20+
table.integer('OwnerId').notNullable();
21+
table.integer('PhotoProjectId').notNullable();
22+
table.integer('Program').notNullable();
23+
table.string('Creator', 256).nullable();
24+
table.string('CommunityName', 256).nullable();
25+
table.string('Location', 256).nullable();
26+
table.integer('UsageRights').nullable();
27+
table.boolean('IsComplete').notNullable();
28+
table.integer('ImageHeight').nullable();
29+
table.integer('ImageWidth').nullable();
30+
table.integer('Rating').nullable();
31+
table.string('Subjects', 500).nullable();
32+
table.string('LegacyBatchInfo', 150).nullable();
33+
table.boolean('IsSiteDefault').notNullable();
34+
table.dateTime('DatePhotoTaken').nullable();
35+
table.boolean('IsPrivate').notNullable();
36+
table.string('Summary', 500).nullable();
37+
});
38+
}
39+
40+
export async function down(knex: Knex): Promise<void> {
41+
await knex.schema.withSchema('dbo').alterTable('Photo', (table) => {
42+
table.dropColumn('Summary');
43+
table.dropColumn('IsPrivate');
44+
table.dropColumn('DatePhotoTaken');
45+
table.dropColumn('IsSiteDefault');
46+
table.dropColumn('LegacyBatchInfo');
47+
table.dropColumn('Subjects');
48+
table.dropColumn('Rating');
49+
table.dropColumn('ImageWidth');
50+
table.dropColumn('ImageHeight');
51+
table.dropColumn('IsComplete');
52+
table.dropColumn('UsageRights');
53+
table.dropColumn('Location');
54+
table.dropColumn('CommunityName');
55+
table.dropColumn('Creator');
56+
table.dropColumn('Program');
57+
table.dropColumn('PhotoProjectId');
58+
table.dropColumn('OwnerId');
59+
table.dropColumn('CreditLine');
60+
table.dropColumn('Copyright');
61+
table.dropColumn('Comments');
62+
table.dropColumn('MediaStorage');
63+
table.dropColumn('OriginalRecord');
64+
table.dropColumn('OriginalMediaId');
65+
table.dropColumn('IsOtherRecord');
66+
table.dropColumn('ArchivalRecord');
67+
table.dropColumn('PaleoRecord');
68+
table.dropColumn('BordenRecord');
69+
table.dropColumn('YHSIRecord');
70+
table.dropColumn('DateCreated');
71+
table.dropColumn('NTSMapNumber');
72+
table.dropColumn('Id');
73+
});
74+
}

api/data/migrations/user_insert.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
import { Knex } from 'knex';
2-
exports.up = async function (knex: Knex, Promise: any) {
3-
await knex.raw(`INSERT INTO Security.[User] (email, first_name, last_name, create_date, roles, status) VALUES
4-
('ryanjagar@gmail.com', 'Ryan', 'Agar', '2023-05-15 14:58:46.000', 'Administrator', 'Active'),
5-
('diedre@driftgeomatics.com', 'Diedre', 'Davidson', '2023-05-16 01:28:18.000', 'Administrator', 'Active'),
6-
('maxrparker@gmail.com', 'Max', 'Parker', '2023-06-06 17:53:18.000', 'Administrator', 'Active')`);
7-
};
2+
exports.up = async function (knex: Knex, Promise: any) {};
83

9-
exports.down = async function (knex: Knex, Promise: any) {
10-
await knex.raw(`DELETE FROM Security.[User] WHERE 1=1`);
11-
};
4+
exports.down = async function (knex: Knex, Promise: any) {};

0 commit comments

Comments
 (0)