Sequelize Express multiple models - express

I can't seem to figure out how to include multiple models.
I have three models.
Tabs, Servers, and Points
Tabs hasMany Server
Servers belongsTo Tabs and hasMany Points
Points belongTo Server
In my routes I am doing this:
router.get('/', function (req, res, next) {
models.TabConfig.findAll({
include: [models.ServerConfig]
}).then(function (tabs) {
res.render('index', {
tabs: tabs,
});
});
});
module.exports = router;
which gets me all the tabs, and the servers associated with them. Works great.
But I want the points associated with the Servers as well so I can iterate over the tabs, servers, and points.
Any ideas?
Thanks

At first glance, you can use eager loading with multiple models:
models.TabConfig.findAll({
include: [{
model: models.ServerConfig,
include: [models.Points]
}]
})
That should give you an array with all the Tabs and its Servers, and inside each Server you will have its points associated to it.
[{
some: 'tab',
saved: 'property',
Servers: [{
some: 'server',
saved: 'property',
Points: [...]
}, ...]
}, ...]

Related

Nestjs + Graphql multiple endpoints issue with first code approach

Despite the search of different issues about this, the bug seems to still keep on existing.
I tried to create a couple of graphQL endpoints, to split admin and "public" resolvers.
In my app.module.ts
ProfileModule,
AdminProfileModule,
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
debug: config.isDev(),
playground: true,
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
context: ({ req }) => ({ req }),
transformAutoSchemaFile: true,
include: [
ProfileModule,
],
}),
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
debug: config.isDev(),
playground: true,
autoSchemaFile: join(process.cwd(), 'src/admin.gql'),
context: ({ req }) => ({ req }),
transformAutoSchemaFile: true,
include: [
AdminProfileModule,
],
}),
While trying to debug I noticed that just the fact to add a GraphQLModule.forRoot, even with an empty includes array, even when not injecting AdminProfileModule, generated the following error :
Schema must contain uniquely named types but contains multiple types named Links
ProfileModule and AdminProfileModule share some schemas, but two resolvers are different but with queries handling same name. For design reasons, I don't wanna change the names.
I think the bug is due to the fact that GraphQL.forRoot doesn't dive into "includes" modules, but check out for all imported modules.
Could you check it out??
Thanks.

Handling thousands of custom routes from a database in Nuxt.js

I have a Nuxt JS (v3) application with thousands of custom routes, many pointing to the same pages, but at the domain root.
e.g /some-product-name-one, /a-secondary-product-name, /some-category-name, /some-static-page.
So in this case, the slug can be anything at domain root level, which is why i must fetch it from my database to assert which component is to be used.
What i've done is fetch all the routes (about 27.000) from my Database via. an API on build in my app/router.options.ts so it looks like so:
import type { RouterOptions } from '#nuxt/schema'
export default <RouterOptions> {
routes: (_routes) => [
{
name: 'product_some-product-name-one',
path: '/some-product-name-one',
component: () => import('~/pages/product.vue'),
props: {
id: '2421'
}
},
{
name: 'category_some-category-name',
path: '/some-category-name',
component: () => import('~/pages/category.vue'),
props: {
id: '45'
}
},
{...}
]
}
Now, the build time was 10 minutes and the application is extremely slow. Navigating to the website timed out.
How can i fetch routes from my database in Nuxt.js and send the user to the correct component?
Rather than baking all of the routes individually into the router, you might want to use a dynamic route such as _id.vue and handle the varying parameter within the component.

Modifying Vue query with beforeEnter

The scenario: I'm replacing one application with another - both have a /search route with potentially very long queries. The new data structure has changed considerably and, unfortunately, some URLs for the old application have been distributed elsewhere containing multiple parameters which no longer exist.
One way to deal with this might be to intercept each call to search and, by means of beforeEnter() modify query by looking up and replacing the offending terms. I'd have thought something like this:
{
name: "search",
path: "/search",
component: Records,
beforeEnter(to, from, next) {
let query = hackSearch(to.query); // replaces the old terms
next({name: 'search', query: query});
}
},
This causes Uncaught (in promise) InternalError: too much recursion, though. But, from what I understand of documentation and examples I've seen, this, or something like it, should work.
It's not great, but I modified hackSearch() so it would return whether or not it had found an offending term and replaced it. This enables the code above to be modified as follows:
{
name: "search",
path: "/search",
component: Records,
beforeEnter(to, from, next) {
let [query, modified] = hackSearch(to.query);
if (modified) {
next({name: 'search', query: query});
}
else {
next();
}
}
},

Only change one viewport in Aurelia router

Good morning, I have my route setup as shown below within Aurelia CLI.
config.map([
{
route: [''],
viewPorts: {
'side': { moduleId: 'side' },
'main': { moduleId: 'main' }
},
title: 'Test',
nav: false,
name: 'Temp'
]);
What I would like to do is based on what I select on my side view, I just want to change the moduleId for main and load that view.
I don't think there's a way to dynamically change the moduleId of a view-port. I see 2 options to solve your proble:
1 - Create another route, changing the moduleId of one of the viewports
2 - Use the layout mechanism and change its content in run time. I recommend you to read http://aurelia.io/hub.html#/doc/article/aurelia/router/latest/router-configuration/10.
I know this is not the answer you were expecting but I hope it helps.

Testing Enyo Applications

I have an enyo kind like this:
enyo.kind({
name:"branding", components: [
{name: "appName", content:"Stars of the East", classes:"heading"},
{content:AppConfig.tagline, classes:"subHeading"}]
});
I am trying to test this kind with the following jasmine describe.
describe("Test Branding Kind", function() {
it("should see enyo component from jasmine", function() {
var branding = enyo.kind({
kind: "branding"
});
expect(branding.$.appName.getContent()).toBe("Stars of the East");
})
});
I am getting an error. Can anyone guide me ?
You need to put your sub-components in a components array (you already have the closing bracket for the array in your code):
enyo.kind({
name:"branding", components: [
{name: "appName", content:"Stars of the East", classes:"heading"},
{content:AppConfig.tagline, classes:"subHeading"}]
});
You need to actually instantiate your kind to test it. enyo.kind() only creates the template. Try:
describe("Test Branding Kind", function() {
it("should see enyo component from jasmine", function() {
var localBranding = new branding();
expect(localBranding.$.appName.getContent()).toBe("Stars of the East");
})
});
You will also have to fix the problem that Art pointed out where you do not have the components block.
You will probably also need to actually render your components if they have UI elements you want to check. You may want to change the localBranding line to:
var localBranding = new branding().renderInto(<some element on your page>);
Finally, we suggest that kind names should be uppercase to distinguish them from instance names. name: "branding" would be name: "Branding" if you follow our advice.