I want to create an expense tracking app but don't know how to make my schema structure.
The layout:
The schema:
module.exports = {
expenseList: [
{
uid: 'some-uid1',
createdAt: 'some-date1',
expenseItems: [
{
date: 'date11',
desc: 'desc11',
amount: 'amount11'
},
{
date: 'date11',
desc: 'desc11',
amount: 'amount11'
}]
},
{
uid: 'some-uid',
createdAt: 'some-date',
expenseItems: [
{
date: 'date1',
desc: 'desc1',
amount: 'amount1'
},
{
date: 'date1',
desc: 'desc1',
amount: 'amount1'
},
{
date: 'date1',
desc: 'desc1',
amount: 'amount1'
}]
}
]
};
How do I change my schema so I can loop through expenses and display createdAt property as a clickable link that redirects to that expense items?
When do I use Arrays and when do I use Objects in my schema?
Where do I need uid (unique ids)?
I will use firebase for this app
You have an expenseList with a date and expenseItems associated with it. You can have a schema roughly like this. expenseList will be an array of objects. Each expenseList is an object containing uid (to uniquely identify the list), createdAt and array of expenseItems with its own set of properties.
expenseList: [{
uid: 'some-uid',
createdAt: 'some-date',
expenseItems: [
{
date: 'date1',
desc: 'desc1',
amount: 'amount1'
},
{
date: 'date1',
desc: 'desc1',
amount: 'amount1'
}
]
}]
You can iterate over this expenseList to display createdAt in your first screen. On clicking of that, depending on the unique id of that expenseList, fetch the expenseList and display the expenseItems on the second screen.
I have not used firebase before, so you might have to tweak the schema a little.
Related
I have been struggling to set a filter a column that has multiple data in Material-table.
The data is below:
data: [
{
id: 1,
staffName: "John",
role: "1"
},
{
id: 2,
staffName: "Smith",
role: "1,2"
},
{
id: 3,
staffName: "Alex",
role: "2"
}
],
role: {
1: "administrator",
2: "sales"
}
};
The column is below:
const columns = [
{ title: "Id", field: "id" , filtering: false},
{ title: "Name", field: "staffName" , filtering: false},
{
title: "Role",
field: "role",
lookup: roles,
render: (data) =>
data.role
.split(",")
.map((s) => roles[s])
.join(", ")
}
];
I want to show John and Smith when administrator is checked to filter in Role,
but it shows only John.
Similarly, when sales is checked only Alex shows up(I want to show both Smith and Alex).
How can I change the filter including data checked?
Link to code sandbox here
I have a collection of users and a document can be as follows...
{
_id: ObjectId('this user id'),
firstName: 'first name of this user',
lastName: 'last name of this user',
tvs: [
{
_id: ObjectId('this tv id'),
brand: 'This tv brand',
size: 'this tv size',
},
{
_id: ObjectId('this other tv id'),
brand: 'this other tv brand',
size: 'this other tv size',
}
]
}
I am having trouble trying to update a document embedded in the array of tvs using only req.body. I managed to be able to update the document based on the tv id by doing the following...
await User.updateOne(
{
_id: req.user.id,
'tvs._id': req.params.id,
},
{
$set: { 'tvs.$.brand': req.body.brand },
}
);
but what I want to do is something like this...
await User.updateOne(
{
_id: req.user.id,
'tvs._id': req.params.id,
},
{
$set: { 'tvs.$': req.body },
}
);
where req.body can have many fields and will only update the fields specified and leave the other ones untouched. Problem is that when I do this it changes my element to have only the id and whatever fields I may have in req.body and gets rid of all the other fields.
I'm using Apollo Client 3 in a react project.
I have a data structure like this:
ROOT_QUERY
getCollection {
__typename: 'Collection',
_id: '123'
tagColorMap: [
{__typename: 'Tag',
name: 'tag1',
color: "#673ab7",
count: 3},
{__typename: 'Tag',
name: 'tag2',
color: '#f44336',
count: 1},
...
]
entries: [
{
__typename: 'Entry',
_id: 'asd'
tags: [tag1, tag2, tag3]
},
{
__typename: 'Entry',
_id: 'qwe'
tags: [tag2, tag3]
},
...
}
}
the data are normalised in the cache.
ROOT_QUERY
getCollection{
"__ref": "Collection:123"
}
Collection:123{
_id: '123'
tagColorMap: [
{__typename: "Tag",
name: "tag1",
color: "#673ab7",
count: 3},
{__typename: "Tag",
name: "tag2",
color: "#f44336",
count: 1},
...
]
entries: [
{
__ref: "Entry:asd"
},
{
__ref: "Entry:qwe"
},
...
]
Entry:asd {
_id: 'asd'
tags: ['tag1', 'tag2', 'tag3']
},
Entry:qwe {
_id: 'qwe'
tags: ['tag2', 'tag3']
},
I performed a mutation, which renames one of the tag, say 'tag1' -> 'tag11', which returns the new tagColorMap;
now I want to change all 'tag1' into 'tag11' in the cache.
I have gone through the official doc and googled it for a while, but still can't find a way to do this.
refetching won't work because the time between the mutation is done and the refetch is done, all the entries that still have tag 'tag1' don't have a corresponding colour in the colour map, it will fallback to default colour, then back to the original colour after the refetch is done.
another way might be that to let the server return the entire collection after the mutation, which is quite a lot of data
so that's why I would like to rename all 'tag1' into 'tag11' in all 'entry" objects directly in cache, but I couldn't find a way to do this... Could anyone help me with this?
thank you very much in advance!
I'm using the new 2019 paypal sdk with React and I'm trying to create an order with 2 line items. When I create an order, I'm able to get the correct total inside paypal and complete a transaction, but on the test users receipt, it just shows the total for 25.99 and no line items. I'm following v2 of their api instructions but no items are showing up.
purchase_units: [{
amount: {
currency_code: 'USD',
value: '25.99',
breakdown: {
item_total: { value: '25.99', currency_code: 'USD' }
}
}
}],
items: [
{
name: 'Watercolor texture kit Vol. 1',
unit_amount: {
value: '16.00',
currency_code: 'USD'
},
quantity: '1',
description: 'test desc',
sku: '222'
},
{
name: 'Skinny jeans',
unit_amount: {
currency_code: 'USD',
value: '9.99'
},
quantity: '1',
description: 'test desc',
sku: '30'
}
],
I know this is old, I had a similar problem. I think the items need to be inside the purchase_units. I also found to work that I need to include the descriptors in quotes - the API docs don't specify this though.
This is what I'm using to make it work:
<script id='paypal-js' src={`https://www.paypal.com/sdk/js?client-id=${PaypalKey}&disable-funding=credit,card&commit=true&merchant-id=${PaypalMerchantId}&locale=en_US&integration-date=2019-11-07`}/>
Integration date makes paypal use different versions of the api depending on the date.
purchase_units: [{
amount: {
currency_code: currency,
value: cart.totalPrice,
breakdown: {
item_total: {
value: cart.totalPrice,
currency_code: currency
}
}
},
invoice_id: Math.random().toString(36).substring(14),
items: getPaypalFormatItems(cart, products),
soft_descriptor: 'Digital Purchase', // appears on CC statement
description: 'Paypal payment'
}],
application_context: {
brand_name: 'Every-Tuesday',
shipping_preference: 'NO_SHIPPING',
user_action: 'PAY_NOW'
}
This is the model I am working with:
name: {
type: String
},
payment: {
id: {
type: String,
required: true
},
cards: [
{
id: {
type: String
},
is_default: {
type: Boolean,
"default": false
}
}
]
}
I want to add a card to the cards array, for example:
card =
id: "some_token"
is_default: true
I am using the update method to push the card to the array, but it won't add the card to the document. Instead, it creates a new document with only those fields:
{
id: "some_token",
is_default: true,
_id: someId
}
Any idea how I can update the actual document I am targeting instead of creating a new document?
Here's my code (using CoffeeScript):
update_where =
payment:
id: "some_id"
update_push =
$push:
'payment.cards':
id: card_token
is_default: false
Customer.update update_where, update_push, {upsert: true}, (err, results) ->
# Do something with the results
Oh… I just noticed my mistake. The problem was in the where statement.
I was doing:
payment:
id: "some_id"
But the right thing to write is the following:
'payment.id': 'some_id'
And it now works!