-
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.
Merge pull request #5 from kantimam/deploy
Deploy
- Loading branch information
Showing
17 changed files
with
287 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
// in posts.js | ||
import * as React from "react"; | ||
import { Create, SimpleForm, TextInput, BooleanInput, DateTimeInput, ReferenceInput, SelectInput } from 'react-admin'; | ||
|
||
|
||
|
||
|
||
|
||
const ApartmentCreate = (props) => ( | ||
<Create title="Create a Building" {...props} > | ||
<SimpleForm> | ||
<TextInput source="name" /> | ||
</SimpleForm> | ||
</Create> | ||
); | ||
|
||
export default ApartmentCreate |
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,20 @@ | ||
// in posts.js | ||
import * as React from "react"; | ||
import { List, Datagrid, TextField, EditButton} from 'react-admin'; | ||
|
||
export const ApartmentList = (props) => ( | ||
<List | ||
{...props} | ||
> | ||
<Datagrid rowClick="show"> | ||
<TextField source="name"/> | ||
<EditButton/> | ||
</Datagrid> | ||
</List> | ||
); | ||
|
||
|
||
|
||
|
||
|
||
export default ApartmentList |
11 changes: 11 additions & 0 deletions
11
client/src/components/apartment/customViews/ApartmentOne.jsx
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,11 @@ | ||
import React from 'react' | ||
|
||
const ApartmentOne = (props) => { | ||
return ( | ||
<div> | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default ApartmentOne |
11 changes: 11 additions & 0 deletions
11
client/src/components/apartment/customViews/ApartmentThree.jsx
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,11 @@ | ||
import React from 'react' | ||
|
||
const ApartmentOne = (props) => { | ||
return ( | ||
<div> | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default ApartmentOne |
11 changes: 11 additions & 0 deletions
11
client/src/components/apartment/customViews/ApartmentTwo.jsx
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,11 @@ | ||
import React from 'react' | ||
|
||
const ApartmentTwo = (props) => { | ||
return ( | ||
<div> | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default ApartmentTwo |
12 changes: 12 additions & 0 deletions
12
client/src/components/building/customViews/BuildingRosenstrasse.jsx
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,12 @@ | ||
import React from 'react' | ||
|
||
const BuildingRosenstrasse = () => { | ||
/* get data for building rosenstrasse */ | ||
return ( | ||
<div> | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default BuildingRosenstrasse |
12 changes: 12 additions & 0 deletions
12
client/src/components/building/customViews/BuildingView.jsx
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,12 @@ | ||
import React from 'react' | ||
|
||
const BuildingView = ({building, ...props}) => { | ||
|
||
return ( | ||
<div> | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default BuildingView |
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
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,106 @@ | ||
import { getRepository } from "typeorm" | ||
import { Request, Response } from "express" | ||
import { Reader } from "../entity/Reader" | ||
import { client } from "../mqtt/connection"; | ||
import { Key } from "../entity/Key"; | ||
import getList from "../util/getList"; | ||
import dateToUnix from "../util/dateToUnix"; | ||
import { ReaderKey } from "../entity/ReaderKey"; | ||
import { Lock } from "../entity/Lock"; | ||
import { Building } from "../entity/Building"; | ||
import { Apartment } from "../entity/Apartment"; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
export async function getApartments(req: Request, res: Response) { | ||
getList(getRepository(Apartment), req, res) | ||
} | ||
|
||
export async function getApartment(req: Request, res: Response){ | ||
try { | ||
const {id}=req.params; | ||
const result = await getRepository(Apartment).findOne(id) | ||
|
||
if(!result){ | ||
return res.status(404).send({message: `could not find building with the provided id ${id}`}) | ||
} | ||
return res.send(result); | ||
} catch (error) { | ||
console.log(error) | ||
res.status(500).send({error: "server error"}) | ||
} | ||
} | ||
|
||
|
||
export async function createApartment(req: Request, res: Response) { | ||
try { | ||
const result=await getRepository(Apartment).save(req.body); | ||
res.send(result) | ||
} catch (error) { | ||
res.status(500).send({ | ||
error: error | ||
}) | ||
} | ||
|
||
} | ||
|
||
export async function editBuilding(req: Request, res: Response) { | ||
// function creates a connection between the reader and key inside the database and sends it over to the reader | ||
try { | ||
const readerId=req.params.id; | ||
if(readerId === undefined){ | ||
throw "please provide a valid reader id" | ||
} | ||
const { body } = req; | ||
if (!body.readerKeys || !Array.isArray(body.readerKeys)){ | ||
return res.status(400).send({error: "invalid request an array readerKeys is required"}) | ||
} | ||
|
||
// there has to be a better option then deleting all the relationships before adding new but this should do for now | ||
getRepository(ReaderKey) | ||
.createQueryBuilder() | ||
.delete() | ||
.from(ReaderKey) | ||
.where("readerId = :readerId", {readerId: readerId}) | ||
.execute(); | ||
|
||
// check if reader with that ip exists | ||
const readerRepo=getRepository(Reader) | ||
const readerResult = await readerRepo.findOne(readerId, {relations: ["readerKeys"]}) | ||
|
||
if (!readerResult) throw "no door found" | ||
|
||
/* if(body.readerName){ | ||
readerResult.readerName=body.readerName; | ||
} */ | ||
readerResult.acctypeName=body.acctypeName || ""; | ||
readerResult.acctype2Name=body.acctype2Name || ""; | ||
readerResult.acctype3Name=body.acctype3Name || ""; | ||
readerResult.acctype4Name=body.acctype4Name || ""; | ||
readerResult.acctype5Name=body.acctype5Name || ""; | ||
readerResult.acctype6Name=body.acctype6Name || ""; | ||
|
||
readerResult.readerKeys=body.readerKeys; | ||
|
||
await readerRepo.save(readerResult) | ||
|
||
return res.send(readerResult) | ||
|
||
} catch (error) { | ||
console.log(error) | ||
res.status(500).send({ | ||
error: "failed to update keys on reader" | ||
}) | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,35 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, JoinColumn, ManyToOne } from "typeorm"; | ||
import { Building } from "./Building"; | ||
import { Lock } from "./Lock"; | ||
|
||
|
||
@Entity() | ||
export class Apartment { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column("varchar", { length: 100, nullable: false, default: "unbekannte Wohnung" }) | ||
name: string; | ||
|
||
@Column("varchar", { nullable: true }) | ||
info: string; | ||
|
||
@Column({ type: "int", nullable: true }) | ||
apartmentLockId: number; | ||
|
||
@ManyToOne(()=> Lock) | ||
@JoinColumn({name: "apartmentLockId"}) | ||
public apartmentLock: Lock; | ||
|
||
|
||
@Column({ type: "int", nullable: true }) | ||
buildingId: number; | ||
|
||
@ManyToOne(()=> Building, building=> building.apartments, { onDelete: 'CASCADE', onUpdate: 'CASCADE' }) | ||
@JoinColumn({name: "buildingId"}) | ||
public building: Building; | ||
|
||
@OneToMany(()=>Lock, lock=>lock.building, { onDelete: 'CASCADE', onUpdate: 'CASCADE' }) | ||
locks: Lock[]; | ||
|
||
} |
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
Oops, something went wrong.