-
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.
[#159] Schema changed, refactored services, added property sector ent…
…ity and classes (api still has a small bug)
- Loading branch information
Showing
26 changed files
with
440 additions
and
225 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,15 +1,19 @@ | ||
const UserFields = { | ||
loginFields : ['email', 'password'], | ||
createFields : ['email', 'password', 'firstName', 'lastName', 'phoneNumber', 'userType'] | ||
} | ||
createFields : ['email', 'password', 'firstName', 'lastName', 'phoneNumber', 'userType'], | ||
}; | ||
|
||
const WorkOrderFields = { | ||
createFields : ['sectorType', 'workOrderType', 'title', 'cause', 'serviceNeeded', | ||
'priorityType', 'description', 'dueDate', 'priceEstimate'] | ||
} | ||
createFields : ['sectorKind', 'workOrderType', 'title', 'cause', 'serviceNeeded', | ||
'priorityType', 'description', 'dueDate', 'priceEstimate'], | ||
}; | ||
|
||
const PropertyFields = { | ||
createFields : ['name', 'propertyType', 'address'] | ||
} | ||
createFields : ['name', 'propertyType', 'address'], | ||
}; | ||
|
||
export {UserFields, WorkOrderFields, PropertyFields}; | ||
const PROPERTY_SECTOR_FIELDS = { | ||
createFields : ['sectorKind'], | ||
}; | ||
|
||
export { UserFields, WorkOrderFields, PropertyFields, PROPERTY_SECTOR_FIELDS }; |
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,32 @@ | ||
import express, { Request, Response } from 'express'; | ||
import { PropertySectorService } from '../services/PropertySectorService'; | ||
import { PropertySectorMapper } from '../entity_mappers/PropertySectorMapper'; | ||
import auth from '../middleware/auth'; | ||
import handleError from '../utils/HttpUtils'; | ||
import validateBody from '../middleware/requestValidation'; | ||
import { PropertySectorDTO } from '../dtos/PropertySectorDTO'; | ||
import { PropertySector } from '../entities/PropertySector'; | ||
import { PROPERTY_SECTOR_FIELDS } from '../constants/BodyFields'; | ||
|
||
const propertySectorService = new PropertySectorService(); | ||
const propertySectorMapper = new PropertySectorMapper(); | ||
|
||
const propertySectorsController = express.Router({ mergeParams: true }); | ||
|
||
propertySectorsController.post('/', validateBody(PROPERTY_SECTOR_FIELDS.createFields), auth, | ||
async (req: Request, res: Response) => { | ||
try { | ||
const propertySectorDTOs : PropertySectorDTO[] = req.body as PropertySectorDTO[]; | ||
const propertySectors : PropertySector[] = await propertySectorService | ||
.createPropertySectors( | ||
Number(req.params.propertyId), | ||
propertySectorDTOs.map(propertySectorDTO => | ||
propertySectorMapper.fromDTO(propertySectorDTO))); | ||
return res.status(200).json(propertySectors.map(propertySector => | ||
propertySectorMapper.toDTO(propertySector))); | ||
} catch (err) { | ||
return handleError(err, res); | ||
} | ||
}); | ||
|
||
export { propertySectorsController }; |
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,10 @@ | ||
import { PropertyDTO } from './PropertyDTO'; | ||
import { SectorDTO } from './SectorDTO'; | ||
|
||
export class PropertySectorDTO { | ||
|
||
id: number; | ||
property: PropertyDTO; | ||
sector: SectorDTO; | ||
sectorKind: string; | ||
} |
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 @@ | ||
export class SectorDTO { | ||
|
||
id: number; | ||
type: string; | ||
kind: string; | ||
|
||
constructor(kind? : string) { | ||
if (kind) { | ||
this.kind = kind; | ||
} | ||
} | ||
} |
This file was deleted.
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,22 @@ | ||
import { Entity, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'; | ||
import { Property } from './Property'; | ||
import { Sector } from './Sector'; | ||
|
||
@Entity({ name: 'property_sectors' }) | ||
export class PropertySector { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@ManyToOne(type => Property) | ||
@JoinColumn({ | ||
name: 'property_id', | ||
}) | ||
property: Property; | ||
|
||
@ManyToOne(type => Sector) | ||
@JoinColumn({ | ||
name: 'sector_id', | ||
}) | ||
sector: Sector; | ||
} |
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 { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
@Entity({ name: 'sectors' }) | ||
export class Sector { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
type: string; | ||
|
||
@Column() | ||
kind: string; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.