-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,210 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import type { AssetGroup } from '../types/recordTypes.js'; | ||
export declare function addAssetGroup(group: AssetGroup, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; | ||
export declare function addAssetGroup(group: Partial<AssetGroup>, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function addAssetGroupMember(groupId: number | string, assetId: number | string, sessionUser: EmileUser): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import { databasePath } from '../helpers/functions.database.js'; | ||
export function addAssetGroupMember(groupId, assetId, sessionUser) { | ||
const emileDB = sqlite(databasePath); | ||
const rightNowMillis = Date.now(); | ||
let result = emileDB | ||
.prepare(`update AssetGroupMembers | ||
set recordDelete_userName = null, | ||
recordDelete_timeMillis = null, | ||
recordUpdate_userName = ?, | ||
recordUpdate_timeMillis = ? | ||
where recordDelete_timeMillis is not null | ||
and groupId = ? | ||
and assetId = ?`) | ||
.run(sessionUser.userName, rightNowMillis, groupId, assetId); | ||
if (result.changes === 0) { | ||
result = emileDB | ||
.prepare(`insert into AssetGroupMembers ( | ||
groupId, assetId, | ||
recordCreate_userName, recordCreate_timeMillis, | ||
recordUpdate_userName, recordUpdate_timeMillis) | ||
values (?, ?, ?, ?, ?, ?)`) | ||
.run(groupId, assetId, sessionUser.userName, rightNowMillis, sessionUser.userName, rightNowMillis); | ||
} | ||
emileDB.close(); | ||
return result.changes > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import sqlite from 'better-sqlite3' | ||
|
||
import { databasePath } from '../helpers/functions.database.js' | ||
|
||
export function addAssetGroupMember( | ||
groupId: number | string, | ||
assetId: number | string, | ||
sessionUser: EmileUser | ||
): boolean { | ||
const emileDB = sqlite(databasePath) | ||
|
||
const rightNowMillis = Date.now() | ||
|
||
let result = emileDB | ||
.prepare( | ||
`update AssetGroupMembers | ||
set recordDelete_userName = null, | ||
recordDelete_timeMillis = null, | ||
recordUpdate_userName = ?, | ||
recordUpdate_timeMillis = ? | ||
where recordDelete_timeMillis is not null | ||
and groupId = ? | ||
and assetId = ?` | ||
) | ||
.run(sessionUser.userName, rightNowMillis, groupId, assetId) | ||
|
||
if (result.changes === 0) { | ||
result = emileDB | ||
.prepare( | ||
`insert into AssetGroupMembers ( | ||
groupId, assetId, | ||
recordCreate_userName, recordCreate_timeMillis, | ||
recordUpdate_userName, recordUpdate_timeMillis) | ||
values (?, ?, ?, ?, ?, ?)` | ||
) | ||
.run( | ||
groupId, | ||
assetId, | ||
sessionUser.userName, | ||
rightNowMillis, | ||
sessionUser.userName, | ||
rightNowMillis | ||
) | ||
} | ||
|
||
emileDB.close() | ||
|
||
return result.changes > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import type { EnergyAccumulationBehaviour } from '../types/recordTypes.js'; | ||
export declare function addEnergyAccumulationBehaviour(accumulationBehaviour: EnergyAccumulationBehaviour, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; | ||
export declare function addEnergyAccumulationBehaviour(accumulationBehaviour: Partial<EnergyAccumulationBehaviour>, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import type { EnergyCommodity } from '../types/recordTypes.js'; | ||
export declare function addEnergyCommodity(commodity: EnergyCommodity, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; | ||
export declare function addEnergyCommodity(commodity: Partial<EnergyCommodity>, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import type { EnergyDataType } from '../types/recordTypes.js'; | ||
export declare function addEnergyDataType(energyDataType: EnergyDataType, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; | ||
export declare function addEnergyDataType(energyDataType: Partial<EnergyDataType>, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import type { EnergyReadingType } from '../types/recordTypes.js'; | ||
export declare function addEnergyReadingType(readingType: EnergyReadingType, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; | ||
export declare function addEnergyReadingType(readingType: Partial<EnergyReadingType>, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import type { EnergyServiceCategory } from '../types/recordTypes.js'; | ||
export declare function addEnergyServiceCategory(serviceCategory: EnergyServiceCategory, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; | ||
export declare function addEnergyServiceCategory(serviceCategory: Partial<EnergyServiceCategory>, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import type { EnergyUnit } from '../types/recordTypes.js'; | ||
export declare function addEnergyUnit(unit: EnergyUnit, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; | ||
export declare function addEnergyUnit(unit: Partial<EnergyUnit>, sessionUser: EmileUser, connectedEmileDB?: sqlite.Database): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function deleteAssetGroupMember(groupId: number | string, assetId: number | string, sessionUser: EmileUser): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import { databasePath } from '../helpers/functions.database.js'; | ||
export function deleteAssetGroupMember(groupId, assetId, sessionUser) { | ||
const emileDB = sqlite(databasePath); | ||
const result = emileDB | ||
.prepare(`update AssetGroupMembers | ||
set recordDelete_userName = ?, | ||
recordDelete_timeMillis = ? | ||
where recordDelete_timeMillis is null | ||
and groupId = ? | ||
and assetId = ?`) | ||
.run(sessionUser.userName, Date.now(), groupId, assetId); | ||
emileDB.close(); | ||
return result.changes > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sqlite from 'better-sqlite3' | ||
|
||
import { databasePath } from '../helpers/functions.database.js' | ||
|
||
export function deleteAssetGroupMember( | ||
groupId: number | string, | ||
assetId: number | string, | ||
sessionUser: EmileUser | ||
): boolean { | ||
const emileDB = sqlite(databasePath) | ||
|
||
const result = emileDB | ||
.prepare( | ||
`update AssetGroupMembers | ||
set recordDelete_userName = ?, | ||
recordDelete_timeMillis = ? | ||
where recordDelete_timeMillis is null | ||
and groupId = ? | ||
and assetId = ?` | ||
) | ||
.run(sessionUser.userName, Date.now(), groupId, assetId) | ||
|
||
emileDB.close() | ||
|
||
return result.changes > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { Request, Response } from 'express'; | ||
export declare function handler(request: Request, response: Response): void; | ||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { addAssetGroupMember } from '../../database/addAssetGroupMember.js'; | ||
import { getAssets } from '../../database/getAssets.js'; | ||
export function handler(request, response) { | ||
const success = addAssetGroupMember(request.body.groupId, request.body.assetId, request.session.user); | ||
const groupMembers = getAssets({ | ||
groupId: request.body.groupId | ||
}); | ||
response.json({ | ||
success, | ||
groupMembers | ||
}); | ||
} | ||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Request, Response } from 'express' | ||
|
||
import { addAssetGroupMember } from '../../database/addAssetGroupMember.js' | ||
import { getAssets } from '../../database/getAssets.js' | ||
|
||
export function handler(request: Request, response: Response): void { | ||
const success = addAssetGroupMember( | ||
request.body.groupId, | ||
request.body.assetId, | ||
request.session.user as EmileUser | ||
) | ||
|
||
const groupMembers = getAssets({ | ||
groupId: request.body.groupId | ||
}) | ||
|
||
response.json({ | ||
success, | ||
groupMembers | ||
}) | ||
} | ||
|
||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { Request, Response } from 'express'; | ||
export declare function handler(request: Request, response: Response): void; | ||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { deleteAssetGroupMember } from '../../database/deleteAssetGroupMember.js'; | ||
import { getAssets } from '../../database/getAssets.js'; | ||
export function handler(request, response) { | ||
const success = deleteAssetGroupMember(request.body.groupId, request.body.assetId, request.session.user); | ||
const groupMembers = getAssets({ | ||
groupId: request.body.groupId | ||
}); | ||
response.json({ | ||
success, | ||
groupMembers | ||
}); | ||
} | ||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Request, Response } from 'express' | ||
|
||
import { deleteAssetGroupMember } from '../../database/deleteAssetGroupMember.js' | ||
import { getAssets } from '../../database/getAssets.js' | ||
|
||
export function handler(request: Request, response: Response): void { | ||
const success = deleteAssetGroupMember( | ||
request.body.groupId, | ||
request.body.assetId, | ||
request.session.user as EmileUser | ||
) | ||
|
||
const groupMembers = getAssets({ | ||
groupId: request.body.groupId | ||
}) | ||
|
||
response.json({ | ||
success, | ||
groupMembers | ||
}) | ||
} | ||
|
||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
Oops, something went wrong.