juice-shop

Форк
0
/
product-review.service.ts 
41 строка · 1.3 Кб
1
/*
2
 * Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3
 * SPDX-License-Identifier: MIT
4
 */
5

6
import { environment } from '../../environments/environment'
7
import { Injectable } from '@angular/core'
8
import { HttpClient } from '@angular/common/http'
9
import { catchError, map } from 'rxjs/operators'
10

11
@Injectable({
12
  providedIn: 'root'
13
})
14
export class ProductReviewService {
15
  private readonly hostServer = environment.hostServer
16
  private readonly host = this.hostServer + '/rest/products'
17

18
  constructor (private readonly http: HttpClient) { }
19

20
  get (id: number) {
21
    return this.http.get(`${this.host}/${id}/reviews`).pipe(
22
      map((response: any) => response.data), catchError((err: Error) => {
23
        throw err
24
      })
25
    )
26
  }
27

28
  create (id: number, review: { message: string, author: string }) {
29
    return this.http.put(`${this.host}/${id}/reviews`, review).pipe(map((response: any) => response.data),
30
      catchError((err) => { throw err })
31
    )
32
  }
33

34
  patch (review: { id: string, message: string }) {
35
    return this.http.patch(this.host + '/reviews', review).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
36
  }
37

38
  like (_id?: string) {
39
    return this.http.post(this.host + '/reviews', { id: _id }).pipe(map((response: any) => response.data), catchError((err) => { throw err }))
40
  }
41
}
42

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.