-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract.ts
75 lines (73 loc) · 2.9 KB
/
contract.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { defineStore } from 'pinia'
import { useUserStore } from './user'
import { Contract, VersionSummary, Party, IPObject } from '../types/ContractTypes.interface'
export const useContractStore = defineStore({
id: 'contract',
state: () => ({
localContracts: [],
selectedContract: '',
selectedVersion: -1,
comparedVersion: 0
}),
getters: {
getCreatedDate: (state) => {
return (contractName: string): string => {
let contract = state.localContracts.find((contract) => contract.name === contractName);
return contract.versions.at(0).created.toLocaleDateString("es-ES");
}
},
getLastModifiedDate: (state) => {
return (contractName: string): string => {
let contract = state.localContracts.find((contract) => contract.name === contractName);
return contract.versions.at(-1).created.toLocaleDateString("es-ES");
}
},
getContractsBelongingToTheUser(): Contract[] {
const userStore = useUserStore()
let contracts = this.localContracts.filter((contract) => {
return contract.creator === userStore.loggedInUser;
});
return contracts;
},
getContractByName: (state) => {
return (contractName: string): Contract => {
return state.localContracts.find((contract) => contract.name === contractName);
}
},
getVersionListByContractName(): VersionSummary[] {
let contract = this.localContracts.find((contract) => contract.name === this.selectedContract);
let versions = [];
contract.versions.forEach(element => {
versions.push({date: element.created, versionNumber: element.versionNumber})
});
return versions;
}
},
actions: {
setSelectedContract(name: string) {
this.selectedContract = name;
},
setSelectedVersion(num: number) {
this.selectedVersion = num;
},
setComparedVersion(num: number) {
this.comparedVersion = num;
},
createNewContract(newContract: Contract) {
this.localContracts.push(newContract);
},
deleteContract(name: string) {
this.localContracts = this.localContracts.filter((contract) => {
return contract.name !== name;
});
},
addParty(party: Party) {
let contract = this.localContracts.find((contract) => contract.name === this.selectedContract);
contract.versions.at(-1).parties.push(party)
},
addIPObject(ipObject: IPObject) {
let contract = this.localContracts.find((contract) => contract.name === this.selectedContract);
contract.versions.at(-1).ipObjects.push(ipObject)
}
}
})