Skip to content

Commit

Permalink
add comment when copying
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Jul 2, 2024
1 parent 169dc4b commit 7f2d763
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion database/copyLotOccupancy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { dateToString } from '@cityssm/utils-datetime';
import addLotOccupancy from './addLotOccupancy.js';
import addLotOccupancyComment from './addLotOccupancyComment.js';
import addLotOccupancyOccupant from './addLotOccupancyOccupant.js';
import getLotOccupancy from './getLotOccupancy.js';
import { acquireConnection } from './pool.js';
export default async function copyLotOccupancy(oldLotOccupancyId, user) {
const database = await acquireConnection();
const oldLotOccupancy = (await getLotOccupancy(oldLotOccupancyId, database));
const oldLotOccupancy = await getLotOccupancy(oldLotOccupancyId, database);
const newLotOccupancyId = await addLotOccupancy({
lotId: oldLotOccupancy.lotId ?? '',
occupancyTypeId: oldLotOccupancy.occupancyTypeId,
Expand Down Expand Up @@ -43,6 +44,13 @@ export default async function copyLotOccupancy(oldLotOccupancyId, user) {
occupantEmailAddress: occupant.occupantEmailAddress
}, user, database);
}
/*
* Add Comment
*/
await addLotOccupancyComment({
lotOccupancyId: newLotOccupancyId,
lotOccupancyComment: `New record copied from #${oldLotOccupancyId}.`
}, user);
database.release();
return newLotOccupancyId;
}
16 changes: 14 additions & 2 deletions database/copyLotOccupancy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { dateToString } from '@cityssm/utils-datetime'

import type { LotOccupancy } from '../types/recordTypes.js'

import addLotOccupancy from './addLotOccupancy.js'
import addLotOccupancyComment from './addLotOccupancyComment.js'
import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'
import getLotOccupancy from './getLotOccupancy.js'
import { acquireConnection } from './pool.js'
Expand All @@ -11,12 +14,12 @@ export default async function copyLotOccupancy(
): Promise<number> {
const database = await acquireConnection()

const oldLotOccupancy = (await getLotOccupancy(oldLotOccupancyId, database))!
const oldLotOccupancy = await getLotOccupancy(oldLotOccupancyId, database) as LotOccupancy

const newLotOccupancyId = await addLotOccupancy(
{
lotId: oldLotOccupancy.lotId ?? '',
occupancyTypeId: oldLotOccupancy.occupancyTypeId!,
occupancyTypeId: oldLotOccupancy.occupancyTypeId,
occupancyStartDateString: dateToString(new Date()),
occupancyEndDateString: ''
},
Expand Down Expand Up @@ -74,6 +77,15 @@ export default async function copyLotOccupancy(
)
}

/*
* Add Comment
*/

await addLotOccupancyComment({
lotOccupancyId: newLotOccupancyId,
lotOccupancyComment: `New record copied from #${oldLotOccupancyId}.`
}, user)

database.release()

return newLotOccupancyId
Expand Down

0 comments on commit 7f2d763

Please sign in to comment.