How to join firebase data with the newest angularfire and fire util? - firebase

I have a list of categories and a list of products:
{
categories: {
'myCategoryId': {
name: 'my category name',
products: {
'first': true,
'second': true
}
}
},
products: {
'first': {
name: 'my product name',
categoryId: 'myCategoryId'
},
'second': {
name: 'my second product name',
categoryId: 'myCategoryId'
}
}
}
In my sidebar I want to show a joined list of categories with product names so I need some joined structure like:
{
categoriesWithNames: {
'myCategoryId': {
name: 'my category name',
products: {
'first': {
name: 'my product name'
},
'second': {
name: 'my second product name'
},
}
}
}
I know I can do this with Firebase util and AngularFire, but I've tried few different methods and I cannot grasp the concept of joining denormalized data in Firebase. Can anyone help me?
Code
var myApp = angular.module("myApp", ["firebase"]);
var FBURL = "MYFBURL";
var FBEVENTS = {
'deleted':'child_removed',
'added':'child_added'
};
myApp.controller('MyController', ['$scope', '$firebase',
function ($scope, $firebase){
var base = fb(FBURL);
function fb(url) {
return new Firebase(url);
}
function fbChild(attrs) {
return $firebase(typeof attrs === "string" ? base.child(attrs) : base.child(attrs.join("/")));
}
function $a(fbChild) {
return fbChild.$asArray();
}
function $o(fbChild) {
return fbChild.$asObject();
}
var products = fbChild('products');
var categories = fbChild('categories');
$scope.products = $a(products);
$scope.categories = $a(categories);
$scope.products.$loaded().then(function(){
$scope.categories.$watch(function (snapshot) {
console.log('snapshot is', snapshot);
if(snapshot.event!==FBEVENTS.deleted) {
var foundCat = $scope.categories.$getRecord(snapshot.key);
foundCat.products = _.map(foundCat.products, function (val, key){
if (val !== true)
return val;
return $scope.products.$getRecord(key);
});
}
});
});
}

Related

GraphCms publishOrderMutation how to update OrderItem as well

I create a new order after the
payment with stripe, and I update the
stage to published
the brand new order with this code:
const order = {
email: session.customer_email,
total: session.amount_total,
stripeCheckoutId: session.id,
orderItems: {
create: line_items!.data.map((item) => ({
quantity: item.quantity,
total: item.amount_total,
product: {
connect: {
id: (item.price?.product as Stripe.Product).metadata.productId
}
}
}))
}
};
const result = await client
.mutation(CreateOrderMutationDocument, {
order
})
.toPromise();
const id = result.data.order.id;
const result2 = await client
.mutation(PublishOrderMutationDocument, {
id
})
.toPromise();
but how to update OrderItem as well
I've tried with
mutation publishOrderItemMutation($id: ID!) {
publishOrder(where: { order: $id }, to: PUBLISHED) {
id
}
}
but I've got
Error 0: GraphQLDocumentError: Field "order" is not defined by type
"OrderWhereUniqueInput".

filter by category work not properly with remote search?

Hello I have problem compute vue filter by category it work not properly when I add item on Service tab and then click on Medicine tab remote search item by category it will stuck and filter not work and when I click in Service tab back it show only number 2.
this my template
<el-table
:data="itemFilters"
row-key="no"
style="width: 100%"
>
This my script
computed: {
itemFilters() {
const self = this
let item = self.form.items.filter(o => {
return o.categoryName === self.tabActive || o.itemId === ''
})
return item
},
},
this Method
methods: {
_getItemOpts(query, type) {
let exp = new RegExp(query)
let selector = {
$or: [
{ name: { $regex: exp, $options: 'i' } },
{ refNo: { $regex: exp, $options: 'i' } },
{ barcode: { $regex: exp, $options: 'i' } },
],
activityType: { $in: ['Sale'] },
status: 'Active',
'catDoc.name': this.tabActive,
}
// For form Sale Return and receipts refund
if (this.formName == 'Sale_Return' || this.formName == 'Receipt_Refund') {
selector.itemType = { $ne: 'Bundle' }
}
findItems
.callPromise({ selector: selector })
.then(result => {
// this.itemOpts = result
if (type == 'remote') {
// For remote
this.form.items[this.activeIndex].itemOpts = result
} else {
// For scan barcode
let item = result[0]
if (item) {
let row = {
itemId: item._id,
itemType: item.itemType,
memo: '',
qty: 1,
qtyRate: 1,
unitId: item.units[0].unitId,
units: item.units,
price: item.price,
amountBeforeDiscount: item.price,
discountRate: 0,
discountValue: 0,
amountAfterDiscount: item.price,
taxId: '',
taxAmount: 0,
// For expand bundle item
subItems: [],
expand: 'expand',
// For sales only(cash sales and invoice)
// refSaleOrderId: '',
// refSaleOrderDetailId: '',
// refNo: '',
itemOpts: result,
}
this.form.items.push(row)
} else {
Notify.warning({ message: 'This item do not set barcode!' })
}
}
this.loading = false
})
.catch(err => {
this.loading = false
this.$notify.error(err.reason)
})
},
}
Please help...

Akryum: Vuex#1 for Meteor example app, addTrackers?

I don't really understand any of this from https://github.com/Akryum/meteor-vuex-example/tree/master/imports/vuex/modules: from init(data) all the way to if data in getters at the bottom references to vue instance data or state of vuex.
subModule.addTrackers({
selectedThread() {
let sub;
return {
init(data) {
data.selectedThread = null;
data.posts = [];
},
watch(state) {
// Dynamic subscription
if(sub) {
sub.stop();
}
if(state.selectedThreadId) {
sub = Meteor.subscribe('posts', state.selectedThreadId);
console.log('subscribed posts to thread ', state.selectedThreadId);
}
return {
id: state.selectedThreadId
}
},
update(data, {id}) {
data.selectedThread = Object.freeze(Threads.findOne({
_id: id
}));
data.posts = Object.freeze(Posts.find({
thread_id: id
}, {
sort: {created: -1}
}).fetch());
console.log('posts', data.posts);
},
getters: {
getSelectedThread: data => data.selectedThread,
getPosts: data => data.posts
}
}
}
})

Import/Use XrmServiceToolkit on Microsoft CRM 2013

how I use XrmServiceToolkit? Where I import this solution on Microsoft CRM 2013?
Hope this helps you. This is having all information related to xrmservicetoolkit.
https://xrmservicetoolkit.codeplex.com/
http://sumedha8.blogspot.in/2014/03/rest-functions-from-xrmservicetoolkit.html
Add the libraryto your CRM form:
Sample code to use the library:
function Retrieve() {
var re;
XrmServiceToolkit.Rest.Retrieve(
"{EE81D2A9-E28E-E311-96DF-D89D6765B238}",
"AccountSet",
null, null,
function (result) {
re = result;
alert("success");
},
function (error) {
alert("failed");
},
false
);
//debugger;
alert(re.Name);
alert(re.AccountId);
}
function Delete() {
XrmServiceToolkit.Rest.Delete(
"{32815A55-19AF-E311-BF0E-D89D6765B238}",
"AccountSet",
function () {
alert("successfully deleted");
},
function (error) {
alert("failed to delete");
},
false
);
}
function Update() {
var account = {};
account.Name = "SO and Company A1";
account.Address1_AddressTypeCode = { Value: 3 }; //Address 1: Address Type = Primary
account.Address1_City = "Wentworthville";
account.Address1_Line1 = "153 Dunmore Stret";
XrmServiceToolkit.Rest.Update(
"{EE81D2A9-E28E-E311-96DF-D89D6765B238}",
account,
"AccountSet",
function () {
alert("successfully Updated");
},
function (error) {
alert("failed to Update");
},
false
)
}
function Create() {
var account = {};
account.Name = "SO and Company B1";
account.Address1_AddressTypeCode = { Value: 3 }; //Address 1: Address Type = Primary
account.Address1_City = "Wentworthville B";
account.Address1_Line1 = "153 Dunmore Stret B";
XrmServiceToolkit.Rest.Create(
account,
"AccountSet",
function (result) {
accountId = result.AccountId;
alert("successfully Created. Acc ID : " + result.AccountId);
},
function (error) {
alert("failed to Create Account");
},
false
);
}

Using Firebase-util to resolve one to many relationship

I've been looking at the firebase util project at https://firebase.github.io/firebase-util/. I can't figure out if this is possible.
Say I have a data set like this:
{ clients:
{ client1: { groups: { group1: true, group2: true }, name: 'client1' },
client2: { groups: { group3: true, group4: true }, name: 'client2' } },
groups:
{ group1: { name: 'group1' },
group2: { name: 'group2' },
group3: { name: 'group3' },
group4: { name: 'group4' },
group5: { name: 'group5' } } }
I want to retrieve "client1" and resolve all the groups associated with client1, giving me back a dataset like this.
{ client1: { groups: { group1: { name: 'group1' }, group2: { name: 'group2' } }, name: 'client1' }
Is there a way to do this with Firebase-util?
There is an example on the website that is similar, where it is joining an account to a profile and then mapping the style to another reference point.
var ref = Firebase.util.join(
new Firebase('INSTANCE/account'),
{
ref: new Firebase('INSTANCE/profile'),
keyMap: {
name: 'name',
nick: 'nick',
style: new Firebase('INSTANCE/styles')
}
}
);
But, I'm not seeing how to do it with what I'm looking for.
Something like:
FirebaseUtil.join(
{ ref: new Firebase('INSTANCE/clients/client1'), keyMap: {name: 'name', groups: new Firebase('INSTANCE/groups')} }
)
Thanks for any hints!
You cannot use a nested list of groups as the keymap for clients/$client/groups. It must be a string pointing to exactly one reference.
The solution would be to retrieve the list separately from the meta data for the user:
var fb = new Firebase(URL);
getClients(fb.child('clients'), function(userId, data) {
console.log(userId, data);
});
function getGroupsForClient(clientId, callback) {
var indexRef = fb.child('clients/'+clientId+'/groups');
var groupsRef = fb.child('groups');
var intersectionRef = new Firebase.util.intersection(indexRef, groupsRef);
intersectionRef.once('value', callback);
}
function getClients(callback) {
fb.child('clients').on('child_added', function(snap) {
var userId = snap.name();
var userData = snap.val();
getGroupsForClient(userId, function(snap) {
userData.groups = snap.val();
callback(userId, userData);
});
});
}

Resources