mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
fix add anonymous comment
This commit is contained in:
parent
9cbca21aeb
commit
bbebaa4aae
@ -1,3 +1,7 @@
|
||||
export interface CommentDTO {
|
||||
pseudo: string;
|
||||
text: string;
|
||||
}
|
||||
export class Comment {
|
||||
constructor(public id: string, public text: string, public pseudo: string, public created_at: string) {}
|
||||
|
||||
|
@ -6,7 +6,7 @@ export class Stack {
|
||||
public custom_url: string;
|
||||
public pass_hash: string;
|
||||
public pseudo = 'Choque Nourrice';
|
||||
public comment = 'Le beau commentaire de Choque Nourrice';
|
||||
public comment = 'Le beau commentaire tout neuf';
|
||||
public owner: Owner = new Owner();
|
||||
public votes: Vote[] = [];
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import { Subscription } from 'rxjs';
|
||||
import { ToastService } from './toast.service';
|
||||
import { LoaderService } from './loader.service';
|
||||
import { Stack } from '../models/stack.model';
|
||||
import { Comment, CommentDTO } from '../models/comment.model';
|
||||
|
||||
const apiVersion = environment.api.versionToUse;
|
||||
const currentApiRoutes = environment.api.version[apiVersion];
|
||||
@ -140,7 +141,7 @@ export class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
public async createComment(slug: string, comment: string): Promise<string> {
|
||||
public async createComment(slug: string, comment: Comment | CommentDTO): Promise<string> {
|
||||
try {
|
||||
return await this.axiosInstance.post(`${this.baseHref}${this.commentsEndpoint}/${slug}`, comment);
|
||||
} catch (error) {
|
||||
@ -293,11 +294,9 @@ export class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
public async deletePollComments(slug: string): Promise<boolean> {
|
||||
public async deletePollComments(admin_key: string): Promise<boolean> {
|
||||
try {
|
||||
const response: AxiosResponse = await this.axiosInstance.delete(
|
||||
`${this.pollsEndpoint}/${slug}${this.commentsEndpoint}`
|
||||
);
|
||||
const response: AxiosResponse = await this.axiosInstance.delete(`${this.pollsEndpoint}/${admin_key}`);
|
||||
return response?.status === 204;
|
||||
} catch (error) {
|
||||
ApiService.handleError(error);
|
||||
|
@ -23,6 +23,7 @@ import { Stack } from '../models/stack.model';
|
||||
import { Vote } from '../models/vote.model';
|
||||
import { ClipboardService } from 'ngx-clipboard';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { CommentDTO } from '../models/comment.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -283,6 +284,10 @@ export class PollService implements Resolve<Poll> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load a poll data and update the current poll of PollService
|
||||
* @param custom_url
|
||||
*/
|
||||
public async loadPollByCustomUrl(custom_url: string): Promise<void> {
|
||||
if (custom_url) {
|
||||
const poll: Poll | undefined = await this.apiService.getPollByCustomUrl(custom_url);
|
||||
@ -321,17 +326,6 @@ export class PollService implements Resolve<Poll> {
|
||||
*/
|
||||
public updateCurrentPoll(poll: Poll, displayToast = false): Poll {
|
||||
console.log('this.storageService.vote_stack.id', this.storageService.vote_stack.id);
|
||||
|
||||
// if (!this.storageService.vote_stack.id || this.storageService.vote_stack.custom_url !== poll.custom_url) {
|
||||
// console.log('set base choices', poll.choices);
|
||||
// // set the choices only the first time the poll loads, or if we changed the poll
|
||||
// console.log(
|
||||
// 'this.storageService.vote_stack.custom_url',
|
||||
// this.storageService.vote_stack.custom_url
|
||||
// );
|
||||
// this.storageService.setChoicesForVoteStack(poll.choices);
|
||||
// }
|
||||
|
||||
this._poll.next(poll);
|
||||
console.log('next poll', poll);
|
||||
|
||||
@ -602,9 +596,16 @@ export class PollService implements Resolve<Poll> {
|
||||
this.toastService.display('Les participations des votants à ce sondage ont été supprimées.');
|
||||
}
|
||||
|
||||
public async addComment(comment: string): Promise<void> {
|
||||
await this.apiService.createComment(this._poll.getValue().custom_url, comment);
|
||||
this.toastService.display('Votre commentaire a été enregistré.');
|
||||
public async addComment(comment: CommentDTO): Promise<void> {
|
||||
await this.apiService.createComment(this._poll.getValue().custom_url, comment).then(
|
||||
(resp) => {
|
||||
console.log('resp', resp);
|
||||
this.loadPollByCustomUrl(this._poll.getValue().custom_url);
|
||||
console.log('resp', resp);
|
||||
this.toastService.display('Votre commentaire a été enregistré.');
|
||||
},
|
||||
(err) => this.apiService.ousideHandleError(err)
|
||||
);
|
||||
}
|
||||
|
||||
public async deleteComments(): Promise<void> {
|
||||
|
@ -41,8 +41,13 @@ export class CommentsComponent {
|
||||
|
||||
addComment() {
|
||||
this.api
|
||||
.createComment(this.pollService._poll.getValue().custom_url, this.storageService.vote_stack.comment)
|
||||
.createComment(this.pollService._poll.getValue().custom_url, {
|
||||
pseudo: this.storageService.vote_stack.pseudo,
|
||||
text: this.storageService.vote_stack.comment,
|
||||
})
|
||||
.then((resp) => {
|
||||
console.log('resp', resp);
|
||||
// this.poll.comments.push()
|
||||
this.toastService.display('commentaire ajouté');
|
||||
})
|
||||
.catch((error) => {
|
||||
|
Loading…
Reference in New Issue
Block a user