How to describe this intricated document structure using aldeed:simple-schema? - javascript

I need this document structure:
lessons.insert({
name: 'some_name',
audio_files: [
[
{
paths: 'paths/to/file1',
transcriptions: [
'Transcript ..........1',
'Transcript ..........2',
'Transcript ..........3',
]
}
],
[
{
paths: 'paths/to/file2',
transcriptions: [
'Transcript ..........1',
'Transcript ..........2',
'Transcript ..........3',
]
}
],
]
});
I tried using the following SimpleSchema to describe it:
audio_files: {
type: [[String]]
}
This is wrong config.
How can I properly make this schema?

audiofiles: {
type: [Object]
},
'audio_files.$.paths': {
type: String
},
'audio_files.$.transcriptions': {
type: [String]
}
Look here for more.

Related

How can I apply the cluster $in with the where in an array type property using strapi V4

My intention is to be able to apply the $in cluster to the categories property, but it is an array type property. I know that my implementation is not correct, that's why I want some solution to my case.
I will appreciate any solution.
Query Example
where: {
$and: [
categories: {
name: {
$in:["fire"],
},
},
]
},
const entries = await strapi.db
.query("api::data.data")
.findMany({
populate: ["*"],
orderBy: "id",
where: {} // todo
});
Entry Example
{
"id": 1,
"description: "....",
"categories": [
{"id": 1, "name": "fire"},
{"id": 2, "name": "water"}
]
}
After several tests my implementation was functional for an array type property.
where: {
$and: [
categories: {
name: {
$in:["fire"],
},
},
]
},
Can you try once with following code?
const entries = await strapi.db
.query("api::data.data")
.findMany({
populate: ["*"],
orderBy: "id",
where: {
$and: [
categories: {
name: {
$in:["fire"],
},
},
]
},
});

How to clear pre-defined blockly custom blocks in Angular

I have some problem initializing custom blocks
I created blockly custom blocks to modal
export const ConditionBlocklyBlock: Block[] = [
{
type: 'SUM_MAT',
message0: '%1 %2 %3',
colour: '#F88370',
tooltip: 'tooltip',
inputsInline: true,
args0: [
{
type: 'input_value',
name: 'first_value'
},
{
type: 'field_dropdown',
name: 'operator',
options: [
[ '>', '>' ],
[ '>=', '>=' ],
[ '<', '<' ],
[ '<=', '<=' ],
[ '==', '==' ]
]
},
{
type: 'input_value',
name: 'second_value'
}
],
output: "Boolean"
},
{
type: 'swapList',
message0: '%1 %2 %3',
colour: '#F88370',
tooltip: 'tooltip',
inputsInline: true,
args0: [
{
type: 'input_value',
name: 'first_value',
check: 'Boolean'
},
{
type: 'field_dropdown',
name: 'logical_operator',
options: [
[ 'AND', 'AND' ],
[ 'OR', 'OR' ],
]
},
{
type: 'input_value',
name: 'second_value',
check: 'Boolean'
}
],
output: 'Boolean'
}
];
const conditionBlocks: Block[] = ConditionBlocklyBlock;
Blockly.defineBlocksWithJsonArray(conditionBlocks);
When the modal is opened, the block is initialized.
The first time it is opened, it is normal, but from the second time on, the following log appears.
Block definition #77 in JSON array overwrites prior definition of "SUM".
Block definition #78 in JSON array overwrites prior definition of "SUM-MAT".
Block definition #79 in JSON array overwrites prior definition of "SUM_MV".
JsonOverwritesLog
Please give me some advice.

Why is my ES6 having different exports (exports || exports.default + named) depending on the scope of the import?

I have this in a yargs script:
const pkg = require(join(argv.path, 'package.json'));
const exported = require(join(argv.path, pkg.main));
console.log(exported);
If i try to read this source within the yargs script package pkg.main:
import SiteService, { SiteFunction } from 'site-service';
export const siteService = new SiteService('management', {
id: 1000,
othersIds: 1000,
});
export const siteFunction = new SiteFunction(siteService, {
id: 1000,
othersIds: 1000,
});
export default siteService;
The the value of exported is :
{ siteService:
SiteService {
name: 'management',
config: { id: 1000, othersIds: 1000 },
siteFunctionList: [] },
siteFunction:
SiteFunction {
siteService:
SiteService {
name: 'management',
config: [Object],
siteFunctionList: [] },
config: { id: 1000, othersIds: 1000 } },
default:
SiteService {
name: 'management',
config: { id: 1000, othersIds: 1000 },
siteFunctionList: [] } }
If i read the pkg.main of a different module with this content:
import React from 'react';
import Resource from 'ra-core/lib/Resource';
import Route from 'react-router-dom/Route';
import SiteService, { SiteFunction } from 'site-service';
const siteService = new SiteService('management', {
id: 1000,
otherIds: [1, 2],
});
import {
UsersList,
UsersCreate,
UsersEdit,
UsersShow,
} from './resources/users';
export const siteFunction = new SiteFunction(siteService, ({ pages, roles, permissions }) => [
<Resource
name="users"
list={UsersList}
edit={UsersEdit}
create={UsersCreate}
show={UsersShow}
/>,
], ({ pages, roles }) => [
], ({ pages, roles }) => [
{
name: 'management',
redirect: true,
from: '/management',
to: '/',
description: 'management',
},
]);
export default siteFunction;
I have the following output
SiteFunction {
siteService:
SiteService {
name: 'management',
config: { id: 1000, otherIds: [Array] },
siteFunctionList: [] },
config: [Function] }
Both project babel configuration in babel.config.js:
{
only: [
'src',
'styleguide',
],
comments: false,
presets: [
[
'#babel/preset-env',
{
modules: false,
},
],
'#babel/preset-react',
],
plugins: [
'babel-plugin-array-includes',
'#babel/plugin-transform-runtime',
'#babel/plugin-transform-async-to-generator',
'#babel/plugin-proposal-class-properties',
'#babel/plugin-syntax-dynamic-import',
'#babel/plugin-syntax-import-meta',
'#babel/plugin-proposal-json-strings',
[
'#babel/plugin-proposal-decorators',
{
legacy: true,
},
],
],
env: {
production: {
plugins: [
'babel-plugin-add-module-exports',
'#babel/plugin-transform-modules-commonjs',
],
},
test: {
plugins: [
'#babel/plugin-transform-modules-commonjs',
'babel-plugin-dynamic-import-node',
],
},
},
}
In both case, the pkg.main imported was in ES6 syntax, while the yargs script run was a ES5 transpiled file.
I believe this is not good, am I correct?
Where does the bug happen? Both projects have the same babel configuration.
Within my script, should I assume both cases can happen and should I support both?

Elasticsearch completion by url

Using nodejs elasticsearch api I am trying to get completion by url. The problem is when I am trying to define the way the autocompletion should work, it splits my url in several chuncks, not the whole url:
E,g: URL=https://www.edx.org/course/introduction-mongodb-using-mean-stack-mongodbx-m101x-0
This is the index that I created:
elasticClient.index({
index: indexName,
type: 'mooc',
body: {
name: document.name,
url: document.url,
platform: document.platform,
idMooc: document.idMooc,
platformId: document.platformId,
duration: document.duration,
points: document.points,
tags: document.tags,
dirty: document.dirty,
area: document.area,
description: document.description,
suggest: {
input: document.name.split(' '),
output: document.name,
payload: document || {}
},
urlsuggest:{
input: document.url,
output: document.url,
payload: document || {}
}
}
})
This is my search:
elasticClient.search({
index: indexName,
type: 'mooc',
body: {
query: {
filtered: {
query: {
match: {
// match the query agains all of
// the fields in the posts index
_all: input
}
},
filter: {
// only return documents that the flag dirty is false
term: { dirty: false }
}
}
},
suggest: {
urlsuggest: {
text: input,
term: {
field: 'urlsuggest'
}
}
}
}
})
I got the following urlsuggest:
"suggest":{
"urlsuggest":[
{
"text":"https",
"offset":0,
"length":5,
"options":[
]
},
{
"text":"www",
"offset":8,
"length":3,
"options":[
]
},
{
"text":"edx",
"offset":12,
"length":3,
"options":[
]
},
{
"text":"org",
"offset":16,
"length":3,
"options":[
]
},
{
"text":"course",
"offset":20,
"length":6,
"options":[
]
},
{
"text":"introduction",
"offset":27,
"length":12,
"options":[
]
},
{
"text":"mongodb",
"offset":40,
"length":7,
"options":[
]
},
{
"text":"using",
"offset":48,
"length":5,
"options":[
]
},
{
"text":"mean",
"offset":54,
"length":4,
"options":[
]
},
{
"text":"stack",
"offset":59,
"length":5,
"options":[
]
},
{
"text":"mongodbx",
"offset":65,
"length":8,
"options":[
]
},
{
"text":"m",
"offset":74,
"length":1,
"options":[
]
},
{
"text":"x",
"offset":78,
"length":1,
"options":[
]
}
]
}
Which, for some reason splits my url in many inputs. Apart from that is not finding properly since it does not find any match and my elasticsearch contains that field and was properly populated.

Load JSON in Ext store, associations missing

I'm using Ext 4.1. I have some issues with loading json data with associations. The flat data gets loaded perfectly, only the 'hasMany' doesn't work. (if loaded there nowhere to be found). If a record is loaded I want to be able to get the 2 stores of Attendee's and the 1 store of documents.
I can also change the JSON format to a better format (if you have suggestions let me know!)
I have this json data.
This is my first model:
Ext.define('App.model.package.LabVisit', {
extend: 'Ext.data.Model',
requires: [
'App.model.package.Attendee',
'App.model.package.Document'
],
idProperty: 'labVisitID',
fields: [
{
mapping: 'lab_visit_id',
name: 'labVisitID',
type: 'int'
},
{
mapping: 'lab_id',
name: 'labID',
type: 'int'
},
... some more irrelevant...
{
mapping: 'comments',
name: 'comments'
},
{
name: 'upddate'
}
],
hasMany: [
/* edit: added foreignKey (also tried with: lab_visit_id) */
{ model: 'package.Attendee', name: 'attendeeLabList', associationKey:'attendee_lab', foreignKey: 'labVisitId' },
{ model: 'package.Attendee', name: 'attendeeEmpList', associationKey:'attendee_emp', foreignKey: 'labVisitId' }
{ model: 'package.Document', name: 'document', associationKey:'document' },
]
});
I have following attendee model:
Ext.define('App.model.package.Attendee', {
extend: 'Ext.data.Model',
fields: [
/* edit: added this field */
{
mapping: 'lab_visit_id',
name: 'labVisitId'
},
{
mapping: 'attendee_id',
name: 'AttendeeID'
},
{
mapping: 'first_name',
name: 'firstName'
},
{
mapping: 'last_name',
name: 'lastName'
},
{
name: 'email'
}
]
});
following document model:
Ext.define('App.model.package.Document', {
extend: 'Ext.data.Model',
fields: [
{
mapping: 'document_id',
name: 'docID'
},
{
mapping: 'document_name',
name: 'docName'
},
{
mapping: 'document_mimetype',
name: 'mimeType'
},
{
name: 'uploadID'
}
]
});
Finally my store:
Ext.define('App.store.package.LabVisit', {
extend: 'Ext.data.JsonStore',
requires: [
'App.model.package.LabVisit'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.merge({
storeId: 'labVisitStore',
model: 'App.model.package.LabVisit',
remoteSort: true,
proxy: {
type: 'ajax',
api: {
read: API_URLS.getVisitList //url to the json
},
reader: {
type: 'json',
root: 'rows'
}
}
}, cfg)]);
}
});
Edit:
I've added the foreign key in the model and added it to the hasMany
Still no difference. This is my output:
I also find it a strange: If it's broken I expect an exception. And there are 2 mysterious stores always present but I don't have a clue why or what's the purpose.
The problem was in this part:
hasMany: [
{ model: 'package.Attendee', name: 'attendeeLabList', associationKey:'attendee_lab' },
{ model: 'package.Attendee', name: 'attendeeEmpList', associationKey:'attendee_emp' },
{ model: 'package.Document', name: 'document', associationKey:'document' },
]
#Izhaki helped me a lot. Thanx! Especially with the fiddle. I started there and begun with switching the code with my code piece by piece. Until I saw the model was the problem.
models should be defined like this: App.model.package.Attendee
I think it's sad that the framework doesn't show a significant error/warning if a model isn't recognised/doesn't excist/isn't supplied... But meh, it works now.

Categories