Updated oauth lib. TravelDto no longer necessary.

This commit is contained in:
Eneko Nieto
2021-02-22 00:15:18 +01:00
parent 025796bda8
commit 96792fd2d5
8 changed files with 1813 additions and 461 deletions

2221
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -30,7 +30,7 @@
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1002.1",
"@angular-devkit/build-angular": "^0.1002.2",
"@angular/cli": "^11.1.2",
"@angular/compiler-cli": "~11.1.1",
"@types/jasmine": "~3.5.0",

View File

@@ -1,17 +0,0 @@
import { User, UserId } from './user';
export type TravelId = number;
export class TravelDto {
constructor(
public id: TravelId = -1,
public driverInfo: User = null,
public travelersInfo: User[] = [],
public departureDate: string = '',
public origin: string = '',
public destination: string = '',
public places: number = 0,
public matrixRoomId: string = '',
public description?: string
) { }
}

View File

@@ -1,20 +1,19 @@
import { TravelDto } from './travel-dto';
import { User, UserId } from './user';
export type TravelId = number;
export class Travel extends TravelDto {
constructor(travelDto: TravelDto = null) {
super(travelDto?.id,
travelDto?.driverInfo,
travelDto?.travelersInfo,
travelDto?.departureDate,
travelDto?.origin,
travelDto?.destination,
travelDto?.places,
travelDto?.matrixRoomId,
travelDto?.description);
}
export class Travel {
constructor(
public id: TravelId = -1,
public driverInfo: User = null,
public travelersInfo: User[] = [],
public departureDate: string = '',
public origin: string = '',
public destination: string = '',
public places: number = 0,
public matrixRoomId: string = '',
public description?: string
) { }
availablePlaces(): number {
return this.places - this.travelersInfo.length;

View File

@@ -28,7 +28,7 @@ export class EditTravelComponent implements OnInit {
this.apiService.getTravel(travelId)
.subscribe(res => {
if (res.success) {
this.travel = new Travel(res.data);
this.travel = Object.assign( new Travel(), res.data );
}
else {
console.error('Error getting travel ' + travelId + ': ' + res.error.code + ' ' + res.error.msg);

View File

@@ -79,7 +79,7 @@ export class TravelComponent implements OnInit {
this.apiService.getTravel(this.travelId)
.subscribe(res => {
if (res.success) {
this.travel = new Travel(res.data);
this.travel = Object.assign( new Travel(), res.data );
}
else {
console.error('Error getting travel ' + this.travelId + ': ' + res.error);

View File

@@ -32,7 +32,7 @@ export class AbilityService {
return false;
}
return (travel.driverInfo.id !== user.id) && (! travel.hasTraveler(user.id));
return (travel.driverInfo.id !== user.id) && (! travel.hasTraveler(user.id)) && (travel.availablePlaces() > 0);
}
canLeaveTravel(travel: Travel): boolean {

View File

@@ -8,7 +8,6 @@ import { PUBLIC_API_URL, TRAVEL_API_URL, USER_API_URL } from '../app.config';
import { ListDto } from '../entities/list-dto';
import { User } from '../entities/user';
import { AuthService } from './auth.service';
import { TravelDto } from '../entities/travel-dto';
export type ApiCall<T> = (params?: { [param: string]: any }) => (Observable<ApiResponse<ListDto<T>>>);
@@ -29,7 +28,7 @@ export class ApiService {
}
getTravel = (travelId: TravelId) => {
return this.callApi<TravelDto>(PUBLIC_API_URL + '/travel', { travelId });
return this.callApi<Travel>(PUBLIC_API_URL + '/travel', { travelId });
}
getTravels = (params?: { [param: string]: any }) => {