Meteorjs aggregate in publications - meteor

For this collection:
{
room: 'room1',
owner: 'user1',
time: 'time1'
},
{
room: 'room1',
owner: 'user1',
time: 'time2'
},
{
room: 'room2',
owner: 'user1',
time: 'time3'
},
{
room: 'room2',
owner: 'user1',
time: 'time4'
},
{
room: 'room3',
owner: 'user1',
time: 'time5'
},
{
room: 'room3',
owner: 'user1',
time: 'time6'
}
How can publish data so that it returns the document with greatest time for each room:
{
room: 'room1',
owner: 'user1',
time: 'time2'
},
{
room: 'room2',
owner: 'user1',
time: 'time4'
},
{
room: 'room3',
owner: 'user1',
time: 'time6'
}

Related

How to get transaction date having it's hash at hand?

I'm trying to figure out how to get the time when the transaction was included in block by it's hash on the P-Chain.
I looked into getTx method but the response doesn't include this information:
{
unsignedTx: {
networkID: 5,
blockchainID: '11111111111111111111111111111111LpoYY',
outputs: [],
inputs: [ [Object] ],
memo: '0x44656c656761746564207769746820466967656d6e74277320536c61746520415049',
validator: {
nodeID: 'NodeID-4B4rc5vdD1758JSBYL1xyvE5NHGzz6xzH',
start: 1658162594,
end: 1658252280,
weight: 1000000000
},
stake: [ [Object] ],
rewardsOwner: { addresses: [Array], locktime: 0, threshold: 1 }
},
credentials: [ { signatures: [Array] } ]
}

How to custom GridJs pagination with supabase?

I'm software engineer in Cambodia.
I want to custom Grid.js pagination with supanase, but I faced a problem.
I don't know the solution because it's not in the documentation.
I'm using Nuxt 3
Please tell me how to implement.
The Code is below:
onMounted(() => {
grid.updateConfig({
columns: [
{ name: 'Avatar', id: 'avatar' },
{ name: 'name', id: 'name' },
{ name: 'gender', id: 'gender' },
{ name: 'email', id: 'email' },
{ name: 'phone', id: 'phone' },
{ name: 'address', id: 'address' },
],
pagination: {
enabled: true,
limit: 5,
server: {
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
},
summary: true,
},
server: {
keepalive: true,
data: async (opt) => {
console.log(opt)
const { data: customers, error, count } = await supabase
.from('customers')
.select('id, name, gender, email, phone, address, avatar', { count: 'exact' })
.is('deleted_at', null)
.order('created_at', { ascending: false })
return {
data: customers.map((customer) => [
customer.avatar,
customer.name,
customer.gender,
customer.email,
customer.phone,
customer.address,
]),
total: count,
}
},
},
width: '100%',
search: true,
pagination: true,
fixedHeader: true,
className: {
td: 'sr-td-class',
table: 'sr-table',
},
})
grid.render(table.value)
})
I found resolve:
GridJs configuration:
onMounted(() => {
grid.updateConfig({
columns: [
{ name: 'Avatar', id: 'avatar' },
{ name: 'name', id: 'name' },
{ name: 'gender', id: 'gender' },
{ name: 'email', id: 'email' },
{ name: 'phone', id: 'phone' },
{ name: 'address', id: 'address' },
],
pagination: {
enabled: true,
limit: 5,
server: {
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
},
summary: true,
},
server: {
keepalive: true,
data: async (opt) => {
console.log(opt)
const { data: customers, error, count } = await supabase
.from('customers')
.select('id, name, gender, email, phone, address, avatar', { count: 'exact' })
.is('deleted_at', null)
.order('created_at', { ascending: false })
return {
data: customers.map((customer) => [
customer.avatar,
customer.name,
customer.gender,
customer.email,
customer.phone,
customer.address,
]),
total: count,
}
},
},
width: '100%',
fixedHeader: true,
className: {
td: 'sr-td-class',
table: 'sr-table',
},
})
grid.render(table.value)
})
Then create server/api directory
after create file customers.ts in server/api/ directory
This is code in customers.ts file
import { serverSupabaseUser, serverSupabaseClient } from '#supabase/server'
export default defineEventHandler(async (event) => {
const user = await serverSupabaseUser(event)
const client = serverSupabaseClient(event)
const query = useQuery(event)
const from = query.page ? parseInt(query.page) * parseInt(query.limit) : 0
const to = query.page ? from + parseInt(query.limit) : query.limit
if (!user) {
throw createError({ statusCode: 401, message: 'Unauthorized' })
}
const { data, error, count } = await client
.from('customers')
.select('id, name, gender, email, phone, address, avatar', {
count: 'exact',
})
.is('deleted_at', null)
.order('created_at', { ascending: false })
.range(from, to)
return { customers: data, count }
})

Recursive tree view

I'm new to clarity and want to construct a recursive tree view for the below data. How do i do it ?
parent= [
{
name: "xyz_center",
selected: ClrSelectedState.INDETERMINATE,
subfolders: [
{
name: "DS40G",
selected: ClrSelectedState.INDETERMINATE,
subfolders: [
{
name: "DS50F",
selected: ClrSelectedState.UNSELECTED,
subfolders: [
{
name: "DS50F1",
selected: ClrSelectedState.UNSELECTED
}
],
stores: [
{
name: "DS1",
selected: ClrSelectedState.UNSELECTED
},
{
name: "DS61",
selected: ClrSelectedState.UNSELECTED
},
{
name: "DS71",
selected: ClrSelectedState.SELECTED
},
{
name: "DS81",
selected: ClrSelectedState.UNSELECTED
}
]
}
],
stores: [
{
name: "DS1",
selected: ClrSelectedState.UNSELECTED
},
{
name: "DS61",
selected: ClrSelectedState.UNSELECTED
},
{
name: "DS71",
selected: ClrSelectedState.SELECTED
},
{
name: "DS81",
selected: ClrSelectedState.UNSELECTED
}
]
}
],
stores: [
{
name: "DS1",
selected: ClrSelectedState.UNSELECTED
},
{
name: "DS61",
selected: ClrSelectedState.UNSELECTED
},
{
name: "DS71",
selected: ClrSelectedState.SELECTED
},
{
name: "DS81",
selected: ClrSelectedState.UNSELECTED
}
]
}
];

Javascript serialization params with arrays

I'm creating an App that feeds with Woo commerce. By now I can show the products list and access to a product , but I'm not able to create an order.
This is the function that creates and POST's the order :
this.order = function(products, address, tax, total){
var dfd = $q.defer();
var clientId = 2;
var items =[];
for(var i = 0 ; i<products.length ; i++){
var item = {product_id: products[i].id,
quantity: products[i].qty,
price: products[i].price,
};
items.push(item);
}
$http({
method: 'POST',
url: appConfig.DOMAIN_URL + '/wp-json/wc/v1/orders' ,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
paramSerializer: '$httpParamSerializerJQLike',
params: {
consumer_key: appConfig.KEY,
consumer_secret: appConfig.SECRET_KEY,
line_items: items,
customer_id: 1,
total: total,
status: 'completed',
shipping: {
first_name: address.full_name,
address_1: address.street,
city: address.city,
postcode: address.postal_code,
state: address.state
},
shipping_lines: [
{
method_id: 'flat_rate',
method_title: 'Flat Rate',
total: tax
}
]
}
})
.then(function(res){
dfd.resolve(res);
}, function(error){
dfd.reject(error);
})
return dfd.promise;
}
Response is :
{
"code": "woocommerce_rest_required_product_reference",
"message": "Product ID or SKU is required",
"data": {
"status": 400
}
}
Params seems to be there when I inspect with browser :
Name Value
consumer_key ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
consumer_secret cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
customer_id 1
line_items[][price] 24490
line_items[][product_id] 27
line_items[][quantity] 1
shipping_lines[][method_id] flat_rate
shipping_lines[][method_title] Flat Rate
shipping_lines[][total] 0
status completed
total 24490
I tried hardcoding and using the same data from Woocommerce documentation but the result is the same.
With some combinations throws "product id required" , "quantity required" or "SKU required".
Tried with POSTMAN and order is created with no products.
Any help is appreciated
UPDATE
I tried commenting this line :
paramSerializer: '$httpParamSerializerJQLike',
And now order is created but with no products data, only "non array" params were assigned, so im almost sure is a formatting problem...
Example object :
var data = {
payment_method: 'bacs',
payment_method_title: 'Direct Bank Transfer',
set_paid: true,
billing: {
first_name: 'John',
last_name: 'Doe',
address_1: '969 Market',
address_2: '',
city: 'San Francisco',
state: 'CA',
postcode: '94103',
country: 'US',
email: 'john.doe#example.com',
phone: '(555) 555-5555'
},
shipping: {
first_name: 'John',
last_name: 'Doe',
address_1: '969 Market',
address_2: '',
city: 'San Francisco',
state: 'CA',
postcode: '94103',
country: 'US'
},
line_items: [
{
product_id: 93,
quantity: 2
},
{
product_id: 22,
variation_id: 23,
quantity: 1
}
],
shipping_lines: [
{
method_id: 'flat_rate',
method_title: 'Flat Rate',
total: 10
}
]
};
This was my workaround :
$http({
method: 'POST',
url: appConfig.DOMAIN_URL + '/wp-json/wc/v1/orders' ,
//headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: {'Content-Type': 'application/json'},
//paramSerializer: '$httpParamSerializerJQLike',
params: {
consumer_key: appConfig.KEY,
consumer_secret: appConfig.SECRET_KEY
},
data: {
line_items: items,
customer_id: 1,
status: 'pending',
shipping: {
first_name: address.full_name,
address_1: address.street,
city: address.city,
postcode: address.postal_code,
state: address.state
},
shipping_lines: [
{
method_id: 'flat_rate',
method_title: 'Flat Rate',
total: tax
}
]
}
})
.then(function(res){
dfd.resolve(res);
}, function(error){
dfd.reject(error);
})
return dfd.promise;
}
})
;
Not sure if this is the cleanest way to pass the parameters but I could not understand why paramserializer was not working. I took some code from another sources.
Hope it helps

Meteor Error: User Not Found

I have been working on extending the Meteor.users schema which work fine but after I create the first user in a Meteor.startup() and tried logging in I get a "User Not Found" error. Even though i can see the user in the mongo shell. Here is my schema:
Schemas.User = new SimpleSchema({
username: {
type: String,
optional: true
},
emails: {
type: Array,
optional: true
},
"emails.$": {
type: Object
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date,
optional: true
},
"firstName":{
type: String,
max: 50,
min:2
},
'middleName':{
type: String,
optional: true,
max: 50
},
"lastName":{
type: String,
max: 50,
min:2
},
"gender": {
type: String,
autoform: {
afFieldInput: {type: "select-radio-inline",},
options:
[
{label: "Male", value: "Male"},
{label: "Female", value: "Female"}
]
}
},
"branch": {
type: String,
optional: true,
autoform: {
type: "select",
options: function () {
return CompanyBranches.find().map(function (c) {
return {label: c.companyName+' - '+c.addressCity, value: c._id};
});
}
}
},
"active":{
type: String,
allowedValues: ["Yes","No"],
autoform: {
options: [
{label: "Yes", value: "Yes"},
{label: "No", value: "No"}
],
afFieldInput: {
type: "select-radio-inline"
}
}
},
services: {
type: Object,
optional: true,
blackbox: true
},
roles: {
type: [String],
optional: true,
autoform: {
options: [
{label: "Dashboard", value: "Dashboard"},
{label: "Branches", value: "Branches"},
{label: "User Profile", value: "User Profile"},
{label: "Case Managers", value: "Case Managers"},
{label: "Insurance Company", value: "Insurance Company"},
{label: "Tasks", value: "Tasks"},
{label: "Calendar", value: "Calendar"},
{label: "Contacts", value: "Contacts"},
{label: "Cases", value: "Cases"},
{label: "Requests", value: "Requests"},
{label: "Accounts", value: "Accounts"},
{label: "Reports", value: "Reports"},
{label: "Search", value: "Search"},
{label: "HR", value: "HR"}
],
afFieldInput: {
type: "select-checkbox-inline"
}
}
}
});
Meteor.users.attachSchema(Schemas.User);
This is my Meteor Startup function:
Meteor.startup(function () {
if ( Meteor.users.find().count() === 0 ) {
Accounts.createUser({
username: "leocrawf#gmail.com",
email:"leocrawf#gmail.com",
password: "leoten",
firstName: "Leocrawf",
lastName: "Stewart",
gender:"Male",
active: "Yes"
}, function (error) {
if (error) {
console.log("Cannot create user");
}
});
}
});
on the server i am doing this in the Accounts.onCreateUser():
Accounts.onCreateUser(function(options, user) {
user = options || {};
user.username = options.username;
user.firstName = options.firstName;
user.lastName = options.lastName;
user.active = options.active;
user.gender = options.gender;
// Returns the user object
return user;
});
When I query the mongo shell i get this:
meteor:PRIMARY> db.users.find().pretty()
{
"_id" : "pFurR8iDYWJcX9rus",
"username" : "leocrawf#gmail.com",
"firstName" : "Leocrawf",
"lastName" : "Stewart",
"gender" : "Male",
"active" : "Yes",
"services" : {
"resume" : {
"loginTokens" : [
{
"when" : ISODate("2016-02-05T23:13:38.364Z"),
"hashedToken" : "vs5xVlKL59yVTO/fbKbSnar38I8ILAruj2W1YecQ2Io="
}
]
}
}
}
It doesn't look like you're setting up the profile correctly when creating the user:
Instead of:
Accounts.createUser({
username: "leocrawf#gmail.com",
email:"leocrawf#gmail.com",
password: "leoten",
firstName: "Leocrawf",
lastName: "Stewart",
gender:"Male",
active: "Yes"
},
Try:
Accounts.createUser({
username: "leocrawf#gmail.com",
email: "leocrawf#gmail.com",
password: "leoten",
profile: {
firstName: "Leocrawf",
lastName: "Stewart",
gender: "Male",
active: "Yes"
}
},
Also I recommend active: true instead of active: "Yes" to use a boolean instead of a string. It doesn't look like you've defined active or gender in your schema either btw.

Resources