mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2024-11-10 00:23:58 +00:00
BETTERZON-112: Adding service functions for managing vendor shops (#65)
This commit is contained in:
parent
36173c6117
commit
6b88c48018
6
Backend/src/models/vendors/vendors.router.ts
vendored
6
Backend/src/models/vendors/vendors.router.ts
vendored
|
@ -86,7 +86,7 @@ vendorsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
|||
}
|
||||
});
|
||||
|
||||
// PUT /manage/deactivatelisting
|
||||
// PUT vendors/manage/deactivatelisting
|
||||
vendorsRouter.put('/manage/deactivatelisting', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
|
@ -110,7 +110,7 @@ vendorsRouter.put('/manage/deactivatelisting', async (req: Request, res: Respons
|
|||
}
|
||||
});
|
||||
|
||||
// PUT /manage/shop/deactivate/:id
|
||||
// PUT vendors/manage/shop/deactivate/:id
|
||||
vendorsRouter.put('/manage/shop/deactivate/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
|
@ -133,7 +133,7 @@ vendorsRouter.put('/manage/shop/deactivate/:id', async (req: Request, res: Respo
|
|||
}
|
||||
});
|
||||
|
||||
// PUT /manage/shop/activate/:id
|
||||
// PUT vendors/manage/shop/activate/:id
|
||||
vendorsRouter.put('/manage/shop/activate/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
|
|
|
@ -31,7 +31,7 @@ export class ApiService {
|
|||
* @param id The id of the product to get
|
||||
* @return Observable<Product> An observable containing a single product
|
||||
*/
|
||||
getProduct(id): Observable<Product> {
|
||||
getProduct(id: number): Observable<Product> {
|
||||
try {
|
||||
return this.http.get<Product>((this.apiUrl + '/products/' + id));
|
||||
} catch (exception) {
|
||||
|
@ -45,7 +45,7 @@ export class ApiService {
|
|||
* @param query The search term to match
|
||||
* @return Observable<Product[]> An observable list of products
|
||||
*/
|
||||
getProductsByQuery(query): Observable<Product[]> {
|
||||
getProductsByQuery(query: string): Observable<Product[]> {
|
||||
try {
|
||||
return this.http.get<Product[]>((this.apiUrl + '/products/search/' + query));
|
||||
} catch (exception) {
|
||||
|
@ -90,10 +90,10 @@ export class ApiService {
|
|||
* @param productId The product id of the product to fetch the prices for
|
||||
* @return Observable<Price[]> An observable list of prices
|
||||
*/
|
||||
getLowestPrices(productId): Observable<Price[]> {
|
||||
getLowestPrices(productId: number): Observable<Price[]> {
|
||||
try {
|
||||
let params = new HttpParams();
|
||||
params = params.append('product', productId);
|
||||
params = params.append('product', productId.toString());
|
||||
params = params.append('type', 'lowest');
|
||||
return this.http.get<Price[]>((this.apiUrl + '/prices'), {params});
|
||||
} catch (exception) {
|
||||
|
@ -106,10 +106,10 @@ export class ApiService {
|
|||
* @param productId The product id of the product to get the price for
|
||||
* @return Observable<Price> An observable containing a single price
|
||||
*/
|
||||
getAmazonPrice(productId): Observable<Price> {
|
||||
getAmazonPrice(productId: number): Observable<Price> {
|
||||
try {
|
||||
let params = new HttpParams();
|
||||
params = params.append('product', productId);
|
||||
params = params.append('product', productId.toString());
|
||||
params = params.append('vendor', '1');
|
||||
params = params.append('type', 'newest');
|
||||
return this.http.get<Price>((this.apiUrl + '/prices'), {params});
|
||||
|
@ -123,10 +123,10 @@ export class ApiService {
|
|||
* @param productId The product id of the product to fetch the prices for
|
||||
* @return Observable<Price[]> An observable list of prices
|
||||
*/
|
||||
getCurrentPricePerVendor(productId): Observable<Price[]> {
|
||||
getCurrentPricePerVendor(productId: number): Observable<Price[]> {
|
||||
try {
|
||||
let params = new HttpParams();
|
||||
params = params.append('product', productId);
|
||||
params = params.append('product', productId.toString());
|
||||
params = params.append('type', 'newest');
|
||||
return this.http.get<Price[]>((this.apiUrl + '/prices'), {params});
|
||||
} catch (exception) {
|
||||
|
@ -154,6 +154,87 @@ export class ApiService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all managed vendors
|
||||
* @return Observable<Vendor[]> An observable list of vendors
|
||||
*/
|
||||
getManagedVendors(): Observable<Vendor[]> {
|
||||
try {
|
||||
return this.http.get<Vendor[]>((this.apiUrl + '/vendors/managed'));
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specific vendor info by vendor id
|
||||
* @param id The id of the vendor to get information for
|
||||
* @return Observable<Vendor> An observable containing a single vendor
|
||||
*/
|
||||
getVendorById(id: number): Observable<Vendor> {
|
||||
try {
|
||||
return this.http.get<Vendor>((this.apiUrl + '/vendors/' + id));
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of vendors that match the given search term
|
||||
* @param query The search term to match
|
||||
* @return Observable<Product[]> An observable list of vendors
|
||||
*/
|
||||
getVendorsByQuery(query: string): Observable<Vendor[]> {
|
||||
try {
|
||||
return this.http.get<Vendor[]>((this.apiUrl + '/vendors/search/' + query));
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivates the specified product listing for the specified vendor
|
||||
* @param vendorId The vendor id of the vendor to deactivate the product for
|
||||
* @param productId The product id of the product to deactivate
|
||||
* @return Observable<any> The observable response of the api
|
||||
*/
|
||||
deactivateSingleVendorListing(vendorId: number, productId: number): Observable<any> {
|
||||
try {
|
||||
return this.http.put((this.apiUrl + '/vendors/manage/deactivatelisting'), JSON.stringify({
|
||||
vendor_id: vendorId,
|
||||
product_id: productId
|
||||
}));
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivates the specified vendor completely
|
||||
* @param vendorId The vendor id of the vendor to deactivate
|
||||
* @return Observable<any> The observable response of the api
|
||||
*/
|
||||
deactivateVendor(vendorId: number): Observable<any> {
|
||||
try {
|
||||
return this.http.put((this.apiUrl + '/vendors/manage/shop/deactivate/' + vendorId), JSON.stringify({}));
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the specified vendor completely
|
||||
* @param vendorId The vendor id of the vendor to activate
|
||||
* @return Observable<any> The observable response of the api
|
||||
*/
|
||||
activateVendor(vendorId: number): Observable<any> {
|
||||
try {
|
||||
return this.http.put((this.apiUrl + '/vendors/manage/shop/activate/' + vendorId), JSON.stringify({}));
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ____ _ ___ __
|
||||
/ __ \_____(_)_______ / | / /___ __________ ___ _____
|
||||
|
|
Loading…
Reference in New Issue
Block a user