Cic meta builds
This commit is contained in:
31
apps/cic-meta/src/assets/phone.ts
Normal file
31
apps/cic-meta/src/assets/phone.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { ArgPair, Syncable } from '../sync';
|
||||
import { Addressable, addressToBytes, bytesToHex, toKey } from '../digest';
|
||||
|
||||
class Phone extends Syncable implements Addressable {
|
||||
|
||||
address: string
|
||||
value: number
|
||||
|
||||
constructor(address:string, v:number) {
|
||||
const o = {
|
||||
msisdn: v,
|
||||
}
|
||||
super('', o);
|
||||
Phone.toKey(v).then((phid) => {
|
||||
this.id = phid;
|
||||
this.address = address;
|
||||
});
|
||||
}
|
||||
|
||||
public static async toKey(msisdn:number) {
|
||||
return await toKey(msisdn.toString(), ':cic.msisdn');
|
||||
}
|
||||
|
||||
public key(): string {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Phone,
|
||||
}
|
||||
47
apps/cic-meta/src/assets/user.ts
Normal file
47
apps/cic-meta/src/assets/user.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { ArgPair, Syncable } from '../sync';
|
||||
import { Addressable, addressToBytes, bytesToHex, toAddressKey } from '../digest';
|
||||
|
||||
const keySalt = new TextEncoder().encode(':cic.person');
|
||||
class User extends Syncable implements Addressable {
|
||||
|
||||
address: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
|
||||
constructor(address:string, v:Object={}) {
|
||||
if (v['user'] === undefined) {
|
||||
v['user'] = {
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
}
|
||||
}
|
||||
User.toKey(address).then((uid) => {
|
||||
this.id = uid;
|
||||
this.address = address;
|
||||
});
|
||||
super('', v);
|
||||
}
|
||||
|
||||
public static async toKey(address:string) {
|
||||
return await toAddressKey(address, ':cic.person');
|
||||
}
|
||||
|
||||
public key(): string {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public setName(firstName:string, lastName:string) {
|
||||
//const fn = new ArgPair('user.firstName', firstName)
|
||||
//const ln = new ArgPair('user.lastName', lastName)
|
||||
const n = {
|
||||
'user': {
|
||||
'firstName': firstName,
|
||||
'lastName': lastName,
|
||||
},
|
||||
}
|
||||
//this.update([fn, ln], 'update name');
|
||||
this.replace(n, 'update name');
|
||||
}
|
||||
}
|
||||
|
||||
export { User };
|
||||
Reference in New Issue
Block a user