I have the state like, I don't want to touch the rest of the state but specific property of an object in the state.
export interface User {
name: string;
email: string;
userGroup: string;
notification: boolean;
}
export interface SettingState {
user: User | null,
logs: any[],
trail: any[],
}
I want to update the user notification. Can I use patch for that purpose. I tried following but getting error.
patchNotfication(value: boolean) {
this.patchState({ user.notification: value})
}
and this code snippet gives another error
patchNotfication(value: boolean) {
this.patchState((state) => ({
user: value
}));
}
I get following error
What method would serve me best here?
Related
I want to create a reusable function in Electron.js to handle Saving data irrespective of the model(e.g User, Employee, Product),so I passed Model as an argument, then call the specific Model during when the function is called.
but I get this error
Error: Expected handler to be a function, but found type 'object'
This is my code
const User = require( '../database/models/Users.js');
ipcMain.handle('user:create', saveData(User));
async function saveData(_, data,Model) {
try {
const user = await Model.insert(data);
return user;
} catch (e) {
console.log(e.message);
}
}
ipcMain.handle('user:create', saveData(User)); call function saveData(User) after app is started and it returns object. if you want to assign function to 'user:create' then without parameters it's ipcMain.handle('user:create', saveData); but with parameters it's.
ipcMain.handle('user:create', () => saveData(User));
is the same as
ipcMain.handle('user:create', function () {
return saveData(User)
});
I have the following code:
import { IsNotEmpty, IsArray, ArrayMinSize } from 'class-validator';
import { ApiProperty } from '#nestjs/swagger';
export class PublishDto {
#IsNotEmpty()
#IsArray()
#ArrayMinSize(1)
#ApiProperty({
type: [Product]
})
products: Product[];
}
interface Product {
id: string;
title: string;
sku: string;
stock: number;
description: string;
shortDescription: string;
imagesUrl: string[];
price: number;
department: string;
category: string;
brand: string;
keywords: string[];
isActive: boolean;
}
I'm trying to put the interface Product as a schema on swagger, but it's not working, I am getting an error.
Any idea?
The type property is expecting a value that is available at runtime, for example an actual Class or the Javascript String type. Interfaces exist only at compile time and so they aren't valid to be passed in this way.
You'll have to convert it to a Class if you want to pass it manually otherwise you could take a look at using the NestJS Swagger compiler plugin which uses some cool compile-time magic to automatically try and figure some of this stuff out for you
According to this bug and this bug, ssm.StringListParameter doesn't work in the CDK due to some issues with CFT.
I need to be able to export an arbitrarily length list of subnetIds from one stack and import the list into another using SSM, as the lifetime of subnetIds is completely different than the lifetime of the consumer of subnetIds in a second stack (especially in production, though not in a sandbox). I cannot hard code the subnet IDs, as when creating a sandbox the IDs would vary from sandbox to sandbox. I want the latest version of whatever is in the SSM key.
However, the bugs appear to not be resolvable, and I cannot find a work around.
I tried serializing using JSON, but the item passed around the code is is a late binding Token, which is treated as a string, and the deserialized items is a string [], so it's not possible to get such code to compile.
Here's an example of what I attempted. It doesn't compile:
export function getOtherStackOutputList(stack: cdk.Stack, mangledOtherStackName: string, key: string): string [] {
const globallyUniqueKey = `/${mangledOtherStackName}/${key}`;
const jsonResult = ssm.StringParameter.fromStringParameterName(stack, key + 'SSM', globallyUniqueKey).stringValue;
if (cdk.Token.isUnresolved(jsonResult)) {
return jsonResult;
} else {
const result = JSON.parse(jsonResult);
return result;
}
};
which would be used by code that looks like this:
const efsVpcIsolatedSubnetsIds = StackValueShare.getOtherStackOutputList(this, mangledStackName + efsDbStackSuffix,
'efsTimeSeriesDatabaseVpcIsolatedSubnets');
This works for me:
import { Construct } from '#aws-cdk/core';
import { AwsCustomResource, AwsSdkCall } from '#aws-cdk/custom-resources';
import iam = require("#aws-cdk/aws-iam");
interface SSMParameterReaderProps {
parameterName: string;
region: string;
}
export class SSMParameterReader extends AwsCustomResource {
constructor(scope: Construct, name: string, props: SSMParameterReaderProps) {
const { parameterName, region } = props;
const ssmAwsSdkCall: AwsSdkCall = {
service: 'SSM',
action: 'getParameter',
parameters: {
Name: parameterName
},
region,
physicalResourceId: {id:Date.now().toString()} // Update physical id to always fetch the latest version
};
super(scope, name, { onUpdate: ssmAwsSdkCall,policy:{
statements:[new iam.PolicyStatement({
resources : ['*'],
actions : ['ssm:GetParameter'],
effect:iam.Effect.ALLOW,
}
)]
}});
}
public getParameterValue(): string {
return this.getResponseField('Parameter.Value').toString();
}
}
Is it possible to extend the Auth Service and add additional parameters to it?
Currently trying to extend but encounter error such as below:
ERROR in src/app/service/auth/auth-extend.service.ts(15,3): error TS2416: Property 'authorize' in type 'AuthExtendService' is not assignable to the same property in base type 'AuthService'.
Type '(userId: string, password: string, countryCode: string, businessType: string) => void' is not assignable to type '(userId: string, password: string) => void'.
src/app/service/auth/auth-extend.service.ts(21,7): error TS2345: Argument of type '{ userId: string; password: string; countryCode: string; businessType: string; }' is not assignable to parameter of type '{ userId: string; password: string; countryCode: string; businessType: string; }'.
Object literal may only specify known properties, but 'businessType' does not exist in type '{ userId: string; password: string; countryCode: string; businessType: string; }'. Did you mean to write 'businessType'? "
Any one here to tries to do this, like adding new parameters.
Typescript does not support such an overloading out of the box. One way of doing it would be by using optional parameters such as:
export class AuthExtendService extends AuthService {
authorize(userId: string, password: string, businessType?: string): void {
console.log(businessType);
this.store.dispatch(
new AuthActions.LoadUserToken({
userId: userId,
password: password,
})
);
}
}
This is how you should add extra parameters.
Writing an Angular child component, and can't convince the parent to capture a value emitted through #Output. It throws an error that the receiver _co.pinEvent is undefined. During initialization, though, the debugger shows it successfully making the call. So it's not a simple typo.
Followed every guide and question I could find, cut it down to minimal example, and still can't get it to work. The component reference _co seems to be pointing at something other than the home component.
home.module.ts
...
import { KeypadComponent } from '../keypad/keypad.component';
#NgModule({
...
declarations: [HomePage, KeypadComponent]
})
export class HomePageModule {
digits: number;
title: string;
change: any;
constructor() {
}
pinEvent($event) {
console.log(JSON.stringify($event));
}
}
home.page.html
<ion-content>
<ble-lock-keypad (pinValue)="pinEvent($event)"></ble-lock-keypad>
Once the component is visible, any event emitted
from child causes this pinEvent() call to fail on
an undefined reference.
</ion-content>
keypad.component.ts
#Component({
selector: 'ble-lock-keypad',
templateUrl: './keypad.component.html'
})
export class KeypadComponent {
#Output() pinValue: EventEmitter<string> = new EventEmitter<string>();
constructor() {
}
handleInput(key: string) {
this.pinValue.emit(key);
}
}
keypad.component.html
<ion-button (click)="handleInput('1')">1</ion-button>
Getting really tired of seeing this error:
TypeError: _co.pinEvent is not a function. (In '_co.pinEvent($event)', '_co.pinEvent' is undefined)
Can anyone point out what's going wrong?