@glissandoo/lib 1.78.0 → 1.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/helpers/rates.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { VoteValue } from '../models/Group/Repertory/types';
|
|
1
2
|
export declare const rateSteps: {
|
|
2
|
-
id:
|
|
3
|
+
id: 'love' | 'like' | 'neutral' | 'dislike';
|
|
3
4
|
emoji: string;
|
|
4
|
-
value:
|
|
5
|
-
range: number
|
|
5
|
+
value: VoteValue;
|
|
6
|
+
range: [number, number];
|
|
6
7
|
}[];
|
|
7
8
|
export declare const getStepRating: (rating: number) => {
|
|
8
|
-
id:
|
|
9
|
+
id: 'love' | 'like' | 'neutral' | 'dislike';
|
|
9
10
|
emoji: string;
|
|
10
|
-
value:
|
|
11
|
-
range: number
|
|
11
|
+
value: VoteValue;
|
|
12
|
+
range: [number, number];
|
|
12
13
|
} | undefined;
|
|
@@ -30,9 +30,10 @@ export default class GroupRepertory extends Theme<GroupRepertoryData> {
|
|
|
30
30
|
/** @deprecated use sections */
|
|
31
31
|
get mainFilePath(): string | null;
|
|
32
32
|
get visibility(): GroupRepertoireVisibility;
|
|
33
|
-
get votes(): Record<string,
|
|
33
|
+
get votes(): Record<string, import("./types").VoteValue>;
|
|
34
34
|
get votesCount(): number;
|
|
35
|
-
|
|
35
|
+
get votesCountByValues(): Record<"love" | "like" | "neutral" | "dislike", number>;
|
|
36
|
+
voteByUserId(userId: string): import("./types").VoteValue;
|
|
36
37
|
get rating(): number;
|
|
37
38
|
get events(): string[];
|
|
38
39
|
get eventsTL(): Record<string, import("../../Evento/types").EventTinyData>;
|
|
@@ -15,6 +15,7 @@ const tiny_1 = __importDefault(require("../../Evento/tiny"));
|
|
|
15
15
|
const basic_1 = __importDefault(require("../../Repertory/basic"));
|
|
16
16
|
const types_1 = require("./File/Section/types");
|
|
17
17
|
const types_2 = require("./types");
|
|
18
|
+
const rates_1 = require("../../../helpers/rates");
|
|
18
19
|
class GroupRepertory extends basic_1.default {
|
|
19
20
|
constructor(doc, lang = lang_1.defaultLocale) {
|
|
20
21
|
super(doc);
|
|
@@ -65,14 +66,17 @@ class GroupRepertory extends basic_1.default {
|
|
|
65
66
|
get votesCount() {
|
|
66
67
|
return Object.keys(this.votes).length;
|
|
67
68
|
}
|
|
69
|
+
get votesCountByValues() {
|
|
70
|
+
const existingCounts = (0, lodash_1.countBy)(Object.values(this.votes));
|
|
71
|
+
const allCountsEntries = rates_1.rateSteps.map(({ id, value }) => [id, existingCounts[`${value}`] || 0]);
|
|
72
|
+
return Object.fromEntries(allCountsEntries);
|
|
73
|
+
}
|
|
68
74
|
voteByUserId(userId) {
|
|
69
75
|
return this.votes[userId] || null;
|
|
70
76
|
}
|
|
71
77
|
get rating() {
|
|
72
|
-
const totalVotes = Object.
|
|
73
|
-
|
|
74
|
-
return 0;
|
|
75
|
-
return Math.round((totalVotes / this.votesCount) * 100) / 100;
|
|
78
|
+
const totalVotes = (0, lodash_1.sum)(Object.values(this.votes));
|
|
79
|
+
return totalVotes == 0 ? 0 : Math.round((totalVotes / this.votesCount) * 100) / 100;
|
|
76
80
|
}
|
|
77
81
|
get events() {
|
|
78
82
|
return this.data.events || [];
|
|
@@ -55,6 +55,7 @@ export interface GroupRepertoireFilePathItem {
|
|
|
55
55
|
path: string;
|
|
56
56
|
tag: string;
|
|
57
57
|
}
|
|
58
|
+
export type VoteValue = 1 | 2 | 3 | 4;
|
|
58
59
|
export interface GroupRepertoryData extends ThemeBasicData {
|
|
59
60
|
events: string[];
|
|
60
61
|
eventsTL: Record<string, EventTinyData>;
|
|
@@ -71,7 +72,7 @@ export interface GroupRepertoryData extends ThemeBasicData {
|
|
|
71
72
|
identifyAt: Timestamp | null;
|
|
72
73
|
files: Record<FileId, GroupRepertoireFile>;
|
|
73
74
|
filesPath: Partial<Record<FileSectionId, GroupRepertoireFilePathItem[]>>;
|
|
74
|
-
votes: Record<string,
|
|
75
|
+
votes: Record<string, VoteValue>;
|
|
75
76
|
thumbnailURL: string | null;
|
|
76
77
|
editedAt: Timestamp | null;
|
|
77
78
|
visibility: GroupRepertoireVisibility;
|