Usuaris amb administració, i alguns formularis que ja fan algunes coses

This commit is contained in:
Pasq G 2024-12-02 12:06:04 +01:00
parent 2387c9d931
commit f7d3aec8f9
12 changed files with 1425 additions and 107 deletions

View File

@ -1,5 +1,6 @@
<head>
<title>Meteor App</title>
<title>XaSuMu v0.1</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

View File

@ -0,0 +1,3 @@
import { Mongo } from 'meteor/mongo';
export const NecessitatsCollection = new Mongo.Collection('necessitats');

3
imports/api/tipus.js Normal file
View File

@ -0,0 +1,3 @@
import { Mongo } from 'meteor/mongo';
export const TipusCollection = new Mongo.Collection('tipus');

View File

@ -1,109 +1,26 @@
import React, { Suspense, useEffect, useState, useRef } from 'react';
import React, { Suspense, useEffect, useState, useRef, lazy } from 'react';
import { Meteor } from 'meteor/meteor';
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
import { Login } from './Login';
import { useUserId } from 'meteor/react-meteor-accounts';
import { PoblesCollection } from '/imports/api/pobles.js';
import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense';
import { Pobles } from './Pobles';
import { Necessitats } from './Necessitats';
const Pobles = () => {
const [pobleSeleccionat, setPobleSeleccionat] = useState(null);
useSubscribe('pobles');
const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
const QuadreInfo_Poble = () => {
return <>
{pobleSeleccionat && <h1>{pobleSeleccionat._id}</h1>}
<form action={d => {
try {
Meteor.callAsync('editaOAfigPoble',
{
...pobleSeleccionat || [],
nomPoble: d.get('nomPoble'),
cp: d.get('cp') || "",
comarca: d.get('comarca') || "",
}).then(() => setPobleSeleccionat(null))
.catch(err => console.error(err));
} catch (err) {
alert(err);
console.error(err);
}
}}>
<label htmlFor="nomPoble">Població: </label><input name="nomPoble" type="text" defaultValue={ pobleSeleccionat ? pobleSeleccionat.nomPoble : ""}/><br />
<label htmlFor="comarca">Comarca: </label><input name="comarca" type="text" /><br />
<label htmlFor="cp">Codi Postal: </label><input name="cp" type="text" /><br />
<input type='submit' value="Actualitzar la Població" />
<button onClick={ev => {
ev.preventDefault();
if (confirm(`Vas a eliminar el poble "${pobleSeleccionat.nomPoble}". És una operació irreversible. Procedir?`)) {
Meteor.callAsync('eliminaPoble', pobleSeleccionat._id).catch(err => console.error(err));
setPobleSeleccionat(null);
}
}}>Elimina</button>
</form></>;
};
return <Suspense fallback={<>Carregant...</>} >
<QuadreInfo_Poble />
const Loguejat = lazy(async () => await import('/imports/ui/Loguejat.jsx'));
<ul>{
pobles
.sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase())
.map(pob => <li key={`pob_${pob._id}`}>{pob.nomPoble}<button onClick={() => {setPobleSeleccionat(pob)}}>Edita</button></li>)
}</ul>
</Suspense>;
};
export const App = () => {
const Loguejat = () => {
const user = useTracker("user", async () => await Meteor.userAsync());
// const userId = await Meteor.userAsync();
const userId = useUserId();
return userId ? <div>
<Link to="/pobles" >Pobles</Link>
<button onClick={() => Meteor.logout()} >Logout</button>
<p>- poble (que cada poble només tinga accés a lo del seu poble, la resta de pobles no els han de poder tocar): Alaquàs / Albal / Aldaia / Alfafar / Algemesí / Alginet / Alcàsser / Benetússer / Beniparrell / Carlet / Catarroja / Dosaigües / Godelleta / Guadassuar / Iàtova / L'Alcúdia / Llocnou de la Corona / Massanassa / Paiporta / Parke Alkosa / Picanya / Sedaví / Setaigües / Utiel / València-Castellar Oliveral / València-Forn d'Alcedo / València-La Torre / Xest / Xiva / Llombai / Tremolar </p>
<p>- estat: impossible de trobar / disponible / pendent / enviada / ha arribat (que cada poble puga tocar aquestes opcions dels subministres per al seu poble)</p>
<p>- tipus de subministre: maquinària / menjar i beguda / productes infantils / higiene i neteja / sanitari / roba i calçat / ferramentes / necessitats especials / EPIs / electrònica / per a animals / roba de llit, mantes, cortines i mantells / vaixella i utensilis de cuina / papereria i material escolar / mobiliari i electrodomèstics /altres</p>
<p>- necessitat (que la plataforma et dóne un desplegable amb totes les necessitats que s'han demanat fins ara en eixa categoria i pugues buscar, però també afegir-ne coses noves) - que la plataforma demane en aquest punt que siguen tant específiques com puguen (que no em fiquen com a necessitat "mobles" sinó per exemple "rentadora")</p>
<p>- NOMÉS EN CAS DE MOBILIARI I ELECTRODOMÈSTICS:
---- adreça de la casa o lloc on s'ha de dur (tenda, casa, baix...)
---- que afegisquen dies i horaris en què estaran a eixa adreça
---- especificar que el contacte que afegisquen ha de ser necessàriament de la persona que ho va a rebre en la casa o espai
</p>
- que la plataforma recullga la data en la que es fa una petició de subministres
- que la plataforma recullga la data en la que el subministre es canvia a l'estat "ha arribat)
- Nom del contacte
- Telèfon de contacte
- Punt de descàrrega
I després amb opció de visualitzar totes les necessitats que s'han incorporat prèviament al teu poble i assenyalar "ha arribat" en les que ja no necessites
Nosaltres hauríem de tindre opció de filtrar les necessitats per pobles i condicions (per poder vore, per exemple, totes les necessitats pendents de tots els pobles, o només les necessitats pendents d'Alaquàs)
</div>
: <Link to="/login">Entra o Registra't</Link>
;
};
export const App = () => (
<BrowserRouter>
return <BrowserRouter>
<Routes>
<Route path="/" element={ <Loguejat /> } />
<Route path="/" element={ <Suspense fallback={<>Carregant...</>}>{user ? <Loguejat /> : <Login/>}</Suspense> } />
<Route path="/pobles" element={ <Pobles /> } />
<Route path="/necessitats" element={ <Necessitats /> } />
<Route path="/login" element={ <Login /> } />
</Routes>
</BrowserRouter>
);
};

View File

@ -4,14 +4,14 @@ import { useNavigate } from 'react-router-dom';
import { Meteor } from 'meteor/meteor';
export const Login= () => {
export const Login = () => {
const [isLogin, setIsLogin] = useState( { initialState: true } );
const navigate = useNavigate();
const handleLogin = (e) => {
e.preventDefault();
console.dir(e);
console.dir(e.target.elements.email.value);
// console.dir(e);
// console.dir(e.target.elements.email.value);
// console.dir(e.target.elements.password.value);
const email = e.target.elements.email.value;
const password = e.target.elements.password.value;
@ -27,7 +27,7 @@ export const Login= () => {
const handleRegistration = (e) => {
e.preventDefault();
console.dir(e);
// console.dir(e);
const username = e.target.elements.username.value;
const email = e.target.elements.email.value;
const password = e.target.elements.password.value;
@ -80,7 +80,7 @@ export const Login= () => {
<input id="codi" type="text" />
<br />
<button type="submit">Registrar</button>
<button onClick={() => setIsLogin( true )}>Dialeg d'accés</button>
<button onClick={() => setIsLogin( true )}>Torna per accedir</button>
</form>
);
};

84
imports/ui/Loguejat.jsx Normal file
View File

@ -0,0 +1,84 @@
import React from "react";
import { useUserId } from 'meteor/react-meteor-accounts';
import { Link } from 'react-router-dom';
// import { styled } from 'styled-components'
// if (loguejat)
const BotóSecció = ({titol, linkto}) => {
return <div style={{
border: `1px solid #aaaa`,
borderRadius: `.3rem`,
padding: `.2rem`,
backgroundColor: `lightblue`,
margin: `.5rem`
}}>
<Link to={linkto} >{titol}</Link>
</div>;
};
const SeccióPobles = () => <BotóSecció
titol="Pobles"
linkto="/pobles"
/>;
const SeccióNecessitats = () => <BotóSecció
titol="Necessitats"
linkto="/necessitats"
/>;
const PanellSeccions = ({children}) => {
return <div style={{
display: `flex`,
border: `1px solid #cccc`,
padding: `.5rem`,
borderRadius: `.5rem`,
backgroundColor: `lightslategray`
}}>{children}</div>;
};
const Loguejat = () => {
const userId = useUserId();
return userId ? <div>
<button onClick={() => Meteor.logout()} >Logout</button>
<br /><br />
<PanellSeccions >
<SeccióPobles />
<SeccióNecessitats />
</PanellSeccions>
<p>- poble (que cada poble només tinga accés a lo del seu poble, la resta de pobles no els han de poder tocar): Alaquàs / Albal / Aldaia / Alfafar / Algemesí / Alginet / Alcàsser / Benetússer / Beniparrell / Carlet / Catarroja / Dosaigües / Godelleta / Guadassuar / Iàtova / L'Alcúdia / Llocnou de la Corona / Massanassa / Paiporta / Parke Alkosa / Picanya / Sedaví / Setaigües / Utiel / València-Castellar Oliveral / València-Forn d'Alcedo / València-La Torre / Xest / Xiva / Llombai / Tremolar </p>
<p>- estat: impossible de trobar / disponible / pendent / enviada / ha arribat (que cada poble puga tocar aquestes opcions dels subministres per al seu poble)</p>
<p>- tipus de subministre: maquinària / menjar i beguda / productes infantils / higiene i neteja / sanitari / roba i calçat / ferramentes / necessitats especials / EPIs / electrònica / per a animals / roba de llit, mantes, cortines i mantells / vaixella i utensilis de cuina / papereria i material escolar / mobiliari i electrodomèstics /altres</p>
<p>- necessitat (que la plataforma et dóne un desplegable amb totes les necessitats que s'han demanat fins ara en eixa categoria i pugues buscar, però també afegir-ne coses noves) - que la plataforma demane en aquest punt que siguen tant específiques com puguen (que no em fiquen com a necessitat "mobles" sinó per exemple "rentadora")</p>
<p>- NOMÉS EN CAS DE MOBILIARI I ELECTRODOMÈSTICS:
---- adreça de la casa o lloc on s'ha de dur (tenda, casa, baix...)
---- que afegisquen dies i horaris en què estaran a eixa adreça
---- especificar que el contacte que afegisquen ha de ser necessàriament de la persona que ho va a rebre en la casa o espai
</p>
- que la plataforma recullga la data en la que es fa una petició de subministres
- que la plataforma recullga la data en la que el subministre es canvia a l'estat "ha arribat)
- Nom del contacte
- Telèfon de contacte
- Punt de descàrrega
I després amb opció de visualitzar totes les necessitats que s'han incorporat prèviament al teu poble i assenyalar "ha arribat" en les que ja no necessites
Nosaltres hauríem de tindre opció de filtrar les necessitats per pobles i condicions (per poder vore, per exemple, totes les necessitats pendents de tots els pobles, o només les necessitats pendents d'Alaquàs)
</div>
: <Link to="/login">Entra o Registra't</Link>;
};
export default Loguejat;

159
imports/ui/Necessitats.jsx Normal file
View File

@ -0,0 +1,159 @@
import React, { Suspense, useEffect, useState, useRef, lazy } from 'react';
import { Meteor } from 'meteor/meteor';;
import { NecessitatsCollection } from '/imports/api/necessitats.js';
import { PoblesCollection } from '../api/pobles';
import { TipusCollection } from '../api/tipus';
import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense';
import { Roles } from 'meteor/roles';
// import { useUserId } from 'meteor/react-meteor-accounts';
// import Select from 'react-select'
import CreatableSelect from 'react-select/creatable';
import AsyncCreatableSelect from 'react-select/async-creatable';
export const Necessitats = () => {
// const [permes, setPermes] = useState(false);
const [esEditor, setEsEditor] = useState(false);
const userId = Meteor.userId();
useEffect(() => {
(async () => {
const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]);
setEsEditor(comprovaAdmin);
})();
}, []);
// console.log("isAdmin: ", isAdmin) ;
const [necessitatSeleccionada, setNecessitatSeleccionada] = useState(null);
useSubscribe('necessitats');
const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync());
useSubscribe('pobles');
const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
useSubscribe('tipus');
const tipus = useTracker("tipus", () => TipusCollection.find().fetchAsync());
const filterColors = (inputValue) => {
return colourOptions.filter((i) =>
i.label.toLowerCase().includes(inputValue.toLowerCase())
);
};
const QuadreInfo_Necessitats = () => {
return <div style={{
display: `inline-block`,
border: `1px solid #6666`,
padding: `.5rem`,
borderRadius: `.3em`,
backgroundColor: `lightcyan`
}}>
{ esEditor && <div style={{
color: `red`
}}>ADMINISTRADOR</div> }
{necessitatSeleccionada && <h1>{necessitatSeleccionada._id}</h1>}
<h1>Necessitats</h1>
<form
action={d => {
if (d.get('selTipus'))
try {
Meteor.callAsync('editaOAfigNecessitat', {
...necessitatSeleccionada || [],
titol: d.get('titol'),
tipus: d.get('selTipus') || "",
poble: d.get('selPoble')
})
.then(() => setNecessitatSeleccionada(null))
.catch(err => console.error(err))
;
} catch (err) {
alert(err);
console.error(err);
}
}}
>
<label htmlFor="tipus">Tipus: </label>
{/* Si
l'usuari és ADMINISTRADOR o té permisos de responsabilitat, podrà crear nous Tipus al CREAR o a l'EDITAR
si no
tansols podrà assignar a un tipus predefinit o al de ALTRES
*/}
<AsyncCreatableSelect
name="selTipus"
defaultOptions={tipus.map((v,i) => ({value: v, label: v.titol})) }
onCreateOption={(inputValue) => Meteor.callAsync('afigTipus', {titol: inputValue})}
// loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))}
/>
{/* <select name="selTipus">
<option value="moble">Moble</option>
<option value="maquinari">Maquinari</option>
<option value="menjar">Menjar i beguda</option>
<option value="infantil">Infantils</option>
<option value="higiene">Higiene</option>
</select> */}
<br />
<label htmlFor="titol">Títol: </label>
<input type="text" name='titol' />
<br /><br />
<label htmlFor="poble">Poble: </label>
<CreatableSelect name="selPoble" options={pobles.map((v,i) => ({value: v, label: v.nomPoble})) } />
{/* <select name="selPoble">
{
pobles.map((v,i) => <option key={`optPob${i}`}>{v.nomPoble}</option>)
}
</select> */}
<br />
<input type='submit' value="Enviar" />
{necessitatSeleccionada && esEditor && <button onClick={ev => {
ev.preventDefault();
if (confirm(`Vas a eliminar el poble "${pobleSeleccionat.nomPoble}". És una operació irreversible. Procedir?`)) {
Meteor.callAsync('eliminaPoble', pobleSeleccionat._id).catch(err => console.error(err));
setNecessitatSeleccionada(null);
}
}}>Elimina</button>}
</form>
</div>;
};
return <Suspense fallback={<>Carregant...</>} >
<QuadreInfo_Necessitats />
<br /><br />
{/* <AsyncCreatableSelect
cacheOptions
defaultOptions={tipus.map((v,i) => ({value: v, label: v.titol})) }
loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))}
/> */}
{/* <SelectSearch options={options} value="sv" name="language" placeholder="Choose your language" /> */}
{/* <ul>{
necessitats
.sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase())
.map(pob => <li key={`pob_${pob._id}`}>{pob.nomPoble}{esEditor && <button onClick={() => {setPobleSeleccionat(pob)}}>Edita</button>}</li>)
}</ul> */}
</Suspense>;
};

90
imports/ui/Pobles.jsx Normal file
View File

@ -0,0 +1,90 @@
import React, { Suspense, useEffect, useState, useRef, lazy } from 'react';
import { Meteor } from 'meteor/meteor';
import { PoblesCollection } from '/imports/api/pobles.js';
import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense';
import { Roles } from 'meteor/roles';
// import { useUserId } from 'meteor/react-meteor-accounts';
export const Pobles = () => {
const [pobleSeleccionat, setPobleSeleccionat] = useState(null);
useSubscribe('pobles');
const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
const [esEditor, setEsEditor] = useState(false);
const userId = Meteor.userId();
// console.log("isAdmin: ", isAdmin) ;
// (async () => {
useEffect(() => {
(async () => {
const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]);
setEsEditor(comprovaAdmin);
})();
}, []);
// })();
const QuadreInfo_Poble = () => {
return <div style={{
display: `inline-block`,
border: `1px solid #6666`,
padding: `.5rem`,
borderRadius: `.3em`,
backgroundColor: `lightcyan`
}}>
{ esEditor && <div style={{
color: `red`
}}>ADMINISTRADOR</div> }
{pobleSeleccionat && <h1>{pobleSeleccionat._id}</h1>}
<h1>Pobles</h1>
<form
action={d => {
try {
Meteor.callAsync('editaOAfigPoble',
{
...pobleSeleccionat || [],
nomPoble: d.get('nomPoble'),
cp: d.get('cp') || "",
comarca: d.get('comarca') || "",
}).then(() => setPobleSeleccionat(null))
.catch(err => console.error(err));
} catch (err) {
alert(err);
console.error(err);
}
}}
>
<label htmlFor="nomPoble">Població: </label><input name="nomPoble" type="text" defaultValue={ pobleSeleccionat ? pobleSeleccionat.nomPoble : ""}/><br />
<label htmlFor="comarca">Comarca: </label><input name="comarca" type="text" /><br />
<label htmlFor="cp">Codi Postal: </label><input name="cp" type="text" /><br />
<input type='submit' value="Actualitzar la Població" />
<button onClick={ev => {
ev.preventDefault();
if (confirm(`Vas a eliminar el poble "${pobleSeleccionat.nomPoble}". És una operació irreversible. Procedir?`)) {
Meteor.callAsync('eliminaPoble', pobleSeleccionat._id).catch(err => console.error(err));
setPobleSeleccionat(null);
}
}}>Elimina</button>
</form>
</div>;
};
return <Suspense fallback={<>Carregant...</>} >
{ esEditor && <QuadreInfo_Poble /> }
<ul>{
pobles
.sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase())
.map(pob => <li key={`pob_${pob._id}`}>{pob.nomPoble}{esEditor && <button onClick={() => {setPobleSeleccionat(pob)}}>Edita</button>}</li>)
}</ul>
</Suspense>;
};

957
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,10 @@
"meteor-node-stubs": "^1.2.5",
"react": "19.0.0-rc.1",
"react-dom": "19.0.0-rc.1",
"react-router-dom": "^6.28.0"
"react-router-dom": "^6.28.0",
"react-select": "^5.8.3",
"styled-components": "^6.1.13",
"tailwindcss": "^4.0.0-beta.4"
},
"meteor": {
"mainModule": {

View File

@ -2,6 +2,11 @@ import { Meteor } from 'meteor/meteor';
import { PoblesCollection } from '/imports/api/pobles.js';
import { check } from "meteor/check";
import { Roles } from 'meteor/roles';
import { ROLS_GLOBALS, ROLS_DE_POBLE } from '../imports/roles';
import { NecessitatsCollection } from '../imports/api/necessitats';
import { TipusCollection } from '../imports/api/tipus';
async function insertPoble({ nomPoble, cp, comarca }) {
await PoblesCollection.insertAsync({ nomPoble, cp, comarca, createdAt: new Date() });
}
@ -179,12 +184,58 @@ Meteor.startup(async () => {
return PoblesCollection.find();
});
Meteor.publish("necessitats", function () {
return NecessitatsCollection.find();
});
Meteor.publish("tipus", function () {
return TipusCollection.find();
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
try {
await Roles.createRoleAsync(ROLS_GLOBALS.ADMINISTRADOR, { unlessExists: true });
await Roles.createRoleAsync(ROLS_GLOBALS.USUARI, { unlessExists: true });
await Roles.createRoleAsync(ROLS_DE_POBLE.MONITOR, { unlessExists: true });
await Roles.createRoleAsync(ROLS_DE_POBLE.ENCARREGAT, { unlessExists: true });
await Roles.createRoleAsync(ROLS_DE_POBLE.VOLUNTARI, { unlessExists: true });
await Roles.addRolesToParentAsync([ROLS_DE_POBLE.VOLUNTARI, ROLS_DE_POBLE.ENCARREGAT], ROLS_DE_POBLE.MONITOR);
await Roles.addRolesToParentAsync([ROLS_DE_POBLE.VOLUNTARI, ROLS_DE_POBLE.ENCARREGAT, ROLS_DE_POBLE.MONITOR, ROLS_GLOBALS.USUARI], ROLS_GLOBALS.ADMINISTRADOR);
} catch (err) {
console.error(err.message);
}
// Publish user's own roles
Meteor.publish(null, function () {
if (this.userId) {
return Meteor.roleAssignment.find({ "user._id": this.userId });
}
this.ready();
});
// Publish roles for specific scope
// Meteor.publish("scopeRoles", function (scope) {
// if (this.userId) {
// return Meteor.roleAssignment.find({ scope: scope });
// }
// this.ready();
// });
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Meteor.methods({
'editaOAfigPoble': async function (poble) {
const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
try {
if (poble.nomPoble) {
console.log(`EDICIÓ DE POBLE sol·licitada per a "${poble.nomPoble}". Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
if (esAdmin && poble.nomPoble) {
return await PoblesCollection.upsertAsync(
{
_id: poble._id
@ -204,9 +255,36 @@ Meteor.startup(async () => {
}
},
'eliminaPoble': async function (pobleId) {
'afigNecessitat': async function (necessitat) {
const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
try {
if (pobleId) {
console.log(`CREACIÓ DE NECESSITAT sol·licitada per a "${necessitat.titol}". Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
if (esAdmin && necessitat.titol) {
return await NecessitatsCollection.upsertAsync(
{
_id: necessitat._id
}, {
$set: {
...necessitat,
usuari: Meteor.userId(),
editedAt: new Date()
}
}
);
} else {
throw new Error("No tens permís o el títol no està correcte");
}
} catch (e) {
console.error(e);
}
},
'eliminaPoble': async function (pobleId) {
const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
try {
console.log(`ELIMINACIÓ DE POBLE sol·licitada per a ${pobleId}. Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
if (esAdmin && pobleId) {
return await PoblesCollection.removeAsync(pobleId);
} else {
throw new Error("El nom del poble no és vàlid");
@ -214,7 +292,32 @@ Meteor.startup(async () => {
} catch (e) {
console.error(e);
}
},
'afigTipus': async function (tipus) {
const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
try {
console.log(`CREACIÓ DE TIPUS sol·licitada per a "${tipus.titol}". Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
if (esAdmin && tipus.titol) {
return await TipusCollection.upsertAsync(
{
_id: tipus._id
}, {
$set: {
...tipus,
usuari: Meteor.userId(),
editedAt: new Date()
}
}
);
} else {
throw new Error("El nom del poble no és vàlid");
}
} catch (e) {
console.error(e);
}
},
});
});