119 lines
3.0 KiB
TypeScript
119 lines
3.0 KiB
TypeScript
import { Router } from '@angular/router';
|
|
import { ConsoleFormattedStream, INFO, createLogger as _createLogger, stdSerializers } from 'browser-bunyan';
|
|
import { BusinessListing, CommercialPropertyListing } from '../../../../bizmatch-server/src/models/db.model';
|
|
import { ListingCriteria } from '../../../../bizmatch-server/src/models/main.model';
|
|
|
|
export function createDefaultCommercialPropertyListing(): CommercialPropertyListing {
|
|
return {
|
|
id: undefined,
|
|
userId: '',
|
|
type: null,
|
|
title: '',
|
|
description: '',
|
|
city: '',
|
|
state: '',
|
|
price: null,
|
|
favoritesForUser: [],
|
|
hideImage: false,
|
|
draft: false,
|
|
zipCode: null,
|
|
county: '',
|
|
email: '',
|
|
website: '',
|
|
phoneNumber: '',
|
|
imageOrder: [],
|
|
imagePath: '',
|
|
created: null,
|
|
updated: null,
|
|
visits: null,
|
|
lastVisit: null,
|
|
listingsCategory: 'commercialProperty',
|
|
};
|
|
}
|
|
export function createDefaultBusinessListing(): BusinessListing {
|
|
return {
|
|
id: undefined,
|
|
userId: '',
|
|
type: null,
|
|
title: '',
|
|
description: '',
|
|
city: '',
|
|
state: '',
|
|
price: null,
|
|
favoritesForUser: [],
|
|
draft: false,
|
|
realEstateIncluded: false,
|
|
leasedLocation: false,
|
|
franchiseResale: false,
|
|
salesRevenue: null,
|
|
cashFlow: null,
|
|
supportAndTraining: '',
|
|
employees: null,
|
|
established: null,
|
|
internalListingNumber: null,
|
|
reasonForSale: '',
|
|
brokerLicencing: '',
|
|
internals: '',
|
|
created: null,
|
|
updated: null,
|
|
visits: null,
|
|
lastVisit: null,
|
|
listingsCategory: 'business',
|
|
};
|
|
}
|
|
export function createDefaultListingCriteria(): ListingCriteria {
|
|
return {
|
|
start: 0,
|
|
length: 0,
|
|
page: 0,
|
|
pageCount: 0,
|
|
type: 0,
|
|
state: '',
|
|
minPrice: 0,
|
|
maxPrice: 0,
|
|
realEstateChecked: false,
|
|
title: '',
|
|
category: 'broker',
|
|
name: '',
|
|
};
|
|
}
|
|
export function createLogger(name: string, level: number = INFO, options: any = {}) {
|
|
return _createLogger({
|
|
name,
|
|
streams: [{ level, stream: new ConsoleFormattedStream() }],
|
|
serializers: stdSerializers,
|
|
src: true,
|
|
...options,
|
|
});
|
|
}
|
|
|
|
export const getSessionStorageHandler = function (path, value, previous, applyData) {
|
|
sessionStorage.setItem('criteria', JSON.stringify(this));
|
|
};
|
|
|
|
export function getCriteriaStateObject() {
|
|
const initialState = createDefaultListingCriteria();
|
|
const storedState = sessionStorage.getItem('criteria');
|
|
return storedState ? JSON.parse(storedState) : initialState;
|
|
}
|
|
|
|
export function routeListingWithState(router: Router, value: string, data: any) {
|
|
if (value === 'business') {
|
|
router.navigate(['createBusinessListing'], { state: { data } });
|
|
} else {
|
|
router.navigate(['createCommercialPropertyListing'], { state: { data } });
|
|
}
|
|
}
|
|
|
|
export function resetCriteria(criteria: ListingCriteria) {
|
|
criteria.type = null;
|
|
criteria.state = null;
|
|
criteria.minPrice = null;
|
|
criteria.maxPrice = null;
|
|
criteria.start = null;
|
|
criteria.length = null;
|
|
criteria.realEstateChecked = null;
|
|
criteria.title = null;
|
|
criteria.name = null;
|
|
}
|