Fixed: le reactions devono stare in una tabella a parte (reactions).
- cambiata la gestione dei seen, fav, book, attend
This commit is contained in:
@@ -20,6 +20,8 @@ import { tools } from '@store/Modules/tools'
|
||||
import translate from '@src/globalroutines/util'
|
||||
import { ICallResult, ILinkReg, IResult, IToken } from '@model/other'
|
||||
|
||||
import objectId from '@src/js/objectId'
|
||||
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { serv_constants } from '@store/Modules/serv_constants'
|
||||
@@ -35,13 +37,13 @@ import { Router } from 'vue-router'
|
||||
import { useProjectStore } from '@store/Projects'
|
||||
import { shared_consts } from '@/common/shared_vuejs'
|
||||
import { costanti } from '@costanti'
|
||||
import { IBookmark, ISeen, IFavBook, IAttend, IFavorite, IGroupShort, IMyGroup, IUserAdmins } from '@model/UserStore'
|
||||
import { IReaction, IBookmark, ISeen, IFavBook, IAttend, IFavorite, IGroupShort, IMyGroup, IUserAdmins } from '@model/UserStore'
|
||||
|
||||
import globalroutines from '../globalroutines/index'
|
||||
import { useNotifStore } from '@store/NotifStore'
|
||||
import { useCircuitStore } from './CircuitStore'
|
||||
|
||||
export const CMD_USER = {
|
||||
export const CMD_REACTION = {
|
||||
SET_FAVORITE: 1,
|
||||
SET_BOOKMARK: 2,
|
||||
SET_SEEN: 3,
|
||||
@@ -83,14 +85,12 @@ export const DefaultUser: IUserFields = {
|
||||
asked_groups: [],
|
||||
refused_groups: [],
|
||||
notifs: [],
|
||||
bookmark: [],
|
||||
favorite: [],
|
||||
seen: [],
|
||||
attend: [],
|
||||
myfav: [],
|
||||
mybook: [],
|
||||
myseen: [],
|
||||
myattend: [],
|
||||
// bookmark: [],
|
||||
// favorite: [],
|
||||
// seen: [],
|
||||
// attend: [],
|
||||
reaction: [],
|
||||
myreaction: [],
|
||||
mybookings: [],
|
||||
notif_idCities: [],
|
||||
notif_provinces: [],
|
||||
@@ -157,14 +157,8 @@ export const DefaultProfile: IUserProfile = {
|
||||
asked_groups: [],
|
||||
refused_groups: [],
|
||||
notifs: [],
|
||||
bookmark: [],
|
||||
favorite: [],
|
||||
seen: [],
|
||||
attend: [],
|
||||
myfav: [],
|
||||
mybook: [],
|
||||
myseen: [],
|
||||
myattend: [],
|
||||
reaction: [],
|
||||
myreaction: [],
|
||||
mybookings: [],
|
||||
notif_idCities: [],
|
||||
notif_provinces: [],
|
||||
@@ -1701,21 +1695,29 @@ export const useUserStore = defineStore('UserStore', {
|
||||
console.log('table', table)
|
||||
const tab = tools.getNumTabByTable(table)
|
||||
|
||||
const recreaction = this.getRecReaction(id, table)
|
||||
value = this.isFavorite(id, table) ? false : true
|
||||
|
||||
return await Api.SendReq('/users/cmd', 'POST', { cmd: CMD_USER.SET_FAVORITE, id, tab, value })
|
||||
return await Api.SendReq('/reactions/cmd', 'POST', { cmd: CMD_REACTION.SET_FAVORITE, id, tab, value })
|
||||
.then((res) => {
|
||||
if (res && res.data.state === 1) {
|
||||
if (!myrec.myfav)
|
||||
myrec.myfav = []
|
||||
this.my.profile.favorite.push({ id, tab })
|
||||
if (myrec)
|
||||
myrec.myfav.push({ username: this.my.username })
|
||||
if (myrec) {
|
||||
if (!recreaction)
|
||||
this.my.profile.reaction.push({ id: objectId(), idrec: id, tab, username: this.my.username, fav: true })
|
||||
else
|
||||
recreaction.fav = true;
|
||||
|
||||
myrec.myreact.numfav++
|
||||
}
|
||||
tools.showPositiveNotif($q, t('cmd.favorite_set'))
|
||||
} else if (res && res.data.state === -1) {
|
||||
this.my.profile.favorite = tools.removeIObjectOnce(this.my.profile.favorite, { id, tab })
|
||||
if (myrec && myrec.myfav)
|
||||
myrec.myfav = myrec.myfav.filter((rec: IFavBook) => rec.username !== this.my.username)
|
||||
// this.my.profile.favorite = tools.removeIObjectOnce(this.my.profile.favorite, { id, tab })
|
||||
if (myrec && myrec.myreact.numfav) {
|
||||
myrec.myreact.numfav--
|
||||
//this.my.profile.reaction = this.my.profile.reaction.filter((rec: IReaction) => !((rec.idrec === id) && (rec.tab === tab) && (rec.username === this.my.username) && (rec.fav === true)))
|
||||
if (recreaction)
|
||||
recreaction.fav = false
|
||||
}
|
||||
tools.showNegativeNotif($q, t('cmd.favorite_unset'))
|
||||
}
|
||||
}).catch((error) => {
|
||||
@@ -1731,21 +1733,27 @@ export const useUserStore = defineStore('UserStore', {
|
||||
console.log('table', table)
|
||||
const tab = tools.getNumTabByTable(table)
|
||||
|
||||
const recreaction = this.getRecReaction(id, table)
|
||||
value = this.isAttend(id, table) ? false : true
|
||||
|
||||
return await Api.SendReq('/users/cmd', 'POST', { cmd: CMD_USER.SET_ATTEND, id, tab, value })
|
||||
return await Api.SendReq('/reactions/cmd', 'POST', { cmd: CMD_REACTION.SET_ATTEND, id, tab, value })
|
||||
.then((res) => {
|
||||
if (res && res.data.state === 1) {
|
||||
if (!myrec.myattend)
|
||||
myrec.myattend = []
|
||||
this.my.profile.attend.push({ id, tab, num })
|
||||
if (myrec)
|
||||
myrec.myattend.push({ username: this.my.username })
|
||||
if (!myrec.myreact.attend)
|
||||
myrec.myreact.attend = false
|
||||
// create a record
|
||||
//++ this.my.profile.reaction.push({ id, tab, attend: true })
|
||||
if (myrec) {
|
||||
if (!recreaction)
|
||||
this.my.profile.reaction.push({ id: objectId(), idrec: id, tab, username: this.my.username, attend: true })
|
||||
else
|
||||
recreaction.attend = true
|
||||
}
|
||||
tools.showPositiveNotif($q, t('cmd.attend_set'))
|
||||
} else if (res && res.data.state === -1) {
|
||||
this.my.profile.attend = tools.removeIObjectOnce(this.my.profile.attend, { id, tab })
|
||||
if (myrec && myrec.myattend)
|
||||
myrec.myattend = myrec.myattend.filter((rec: IFavBook) => rec.username !== this.my.username)
|
||||
//++ this.my.profile.attend = tools.removeIObjectOnce(this.my.profile.attend, { id, tab })
|
||||
if (myrec && myrec.myattend && recreaction)
|
||||
recreaction.attend = false
|
||||
tools.showNegativeNotif($q, t('cmd.attend_unset'))
|
||||
}
|
||||
}).catch((error) => {
|
||||
@@ -1755,28 +1763,30 @@ export const useUserStore = defineStore('UserStore', {
|
||||
|
||||
},
|
||||
|
||||
isSeen(id: string, table: string) {
|
||||
getRecReaction(id: string, table: string) {
|
||||
const tab = tools.getNumTabByTable(table)
|
||||
const myseen = this.my.profile.seen.find((rec: ISeen) => ((rec.id === id) && (rec.tab === tab)))
|
||||
return myseen
|
||||
const myrec = this.my.profile.reaction.find((rec: IReaction) => ((rec.idrec === id) && (rec.tab === tab)))
|
||||
return myrec
|
||||
},
|
||||
|
||||
isSeen(id: string, table: string) {
|
||||
const myrec = this.getRecReaction(id, table)
|
||||
return myrec ? myrec.seen : false
|
||||
},
|
||||
|
||||
isBookmarked(id: string, table: string) {
|
||||
const tab = tools.getNumTabByTable(table)
|
||||
const mybookmark = this.my.profile.bookmark.find((rec: IBookmark) => ((rec.id === id) && (rec.tab === tab)))
|
||||
return mybookmark
|
||||
const myrec = this.getRecReaction(id, table)
|
||||
return myrec ? myrec.book : false
|
||||
},
|
||||
|
||||
isFavorite(id: string, table: string) {
|
||||
const tab = tools.getNumTabByTable(table)
|
||||
const myfavorite = this.my.profile.favorite.find((rec: IFavorite) => ((rec.id === id) && (rec.tab === tab)))
|
||||
return myfavorite
|
||||
const myrec = this.getRecReaction(id, table)
|
||||
return myrec ? myrec.fav : false
|
||||
},
|
||||
|
||||
isAttend(id: string, table: string) {
|
||||
const tab = tools.getNumTabByTable(table)
|
||||
const myattend = this.my.profile.attend.find((rec: IAttend) => ((rec.id === id) && (rec.tab === tab)))
|
||||
return myattend
|
||||
const myrec = this.getRecReaction(id, table)
|
||||
return myrec ? myrec.attend : false
|
||||
},
|
||||
|
||||
async setBookmark($q: any, t: any, id: any, table: string, myrec: any) {
|
||||
@@ -1784,21 +1794,27 @@ export const useUserStore = defineStore('UserStore', {
|
||||
|
||||
const tab = tools.getNumTabByTable(table)
|
||||
|
||||
const recreaction = this.getRecReaction(id, table)
|
||||
value = this.isBookmarked(id, table) ? false : true
|
||||
|
||||
return await Api.SendReq('/users/cmd', 'POST', { cmd: CMD_USER.SET_BOOKMARK, id, tab, value })
|
||||
return await Api.SendReq('/reactions/cmd', 'POST', { cmd: CMD_REACTION.SET_BOOKMARK, id, tab, value })
|
||||
.then((res) => {
|
||||
if (res && res.data.state === 1) {
|
||||
if (!myrec.mybook)
|
||||
myrec.mybook = []
|
||||
this.my.profile.bookmark.push({ id, tab })
|
||||
if (myrec)
|
||||
myrec.mybook.push({ username: this.my.username })
|
||||
if (!recreaction)
|
||||
this.my.profile.reaction.push({ id: objectId(), idrec: id, tab, username: this.my.username, book: true })
|
||||
else
|
||||
recreaction.book = true
|
||||
|
||||
myrec.myreact.numbook++
|
||||
tools.showPositiveNotif($q, t('cmd.bookmark_set'))
|
||||
} else if (res && res.data.state === -1) {
|
||||
this.my.profile.bookmark = tools.removeIObjectOnce(this.my.profile.bookmark, { id, tab })
|
||||
if (myrec && myrec.mybook)
|
||||
myrec.mybook = myrec.mybook.filter((rec: IFavBook) => rec.username !== this.my.username)
|
||||
//++ this.my.profile.reaction = tools.removeIObjectOnce(this.my.profile.reaction, { id, tab, })
|
||||
if ((myrec && myrec.mybook) && recreaction)
|
||||
recreaction.book = false
|
||||
myrec.myreact.numbook--
|
||||
//myrec.mybook = myrec.mybook.filter((rec: IFavBook) => rec.username !== this.my.username)
|
||||
tools.showNegativeNotif($q, t('cmd.bookmark_unset'))
|
||||
}
|
||||
}).catch((error) => {
|
||||
@@ -1833,17 +1849,19 @@ export const useUserStore = defineStore('UserStore', {
|
||||
|
||||
const tab = tools.getNumTabByTable(table)
|
||||
|
||||
const recreaction = this.getRecReaction(id, table)
|
||||
value = this.isSeen(id, table) ? false : true
|
||||
|
||||
return await Api.SendReq('/users/cmd', 'POST', { cmd: CMD_USER.SET_SEEN, id, tab, value })
|
||||
return await Api.SendReq('/reactions/cmd', 'POST', { cmd: CMD_REACTION.SET_SEEN, id, tab, value })
|
||||
.then((res) => {
|
||||
if (res && res.data.state === 1) {
|
||||
if (!myrec.myseen)
|
||||
myrec.myseen = []
|
||||
this.my.profile.seen.push({ id, tab })
|
||||
if (myrec)
|
||||
myrec.myseen.push({ username: this.my.username })
|
||||
|
||||
if (value) {
|
||||
myrec.myreact.numseen++
|
||||
if (!recreaction)
|
||||
this.my.profile.reaction.push({ id: objectId(), idrec: id, tab, username: this.my.username, seen: true })
|
||||
else
|
||||
recreaction.seen = true
|
||||
}
|
||||
}
|
||||
if (res && res.data) {
|
||||
if (res.data.record) {
|
||||
|
||||
Reference in New Issue
Block a user