Open jtqfaire opened 2 years ago
Getting same error,
F:\Medusa\Portal\SkryptStore\backend\node_modules\medusa-marketplace\dist\modules\user\user.service.js:26
const validatedId = this.validateId_(userId);
^
TypeError: this.validateId_ is not a function
at UserService.retrieve (F:\Medusa\Portal\SkryptStore\backend\node_modules\medusa-marketplace\dist\modules\user\user.service.js:26:34)
at consume (F:\Medusa\Portal\SkryptStore\backend\node_modules\medusa-marketplace\dist\modules\user\loggedInUser.middleware.js:14:48)
at Layer.handle [as handle_request] (F:\Medusa\Portal\SkryptStore\backend\node_modules\express\lib\router\layer.js:95:5)
at next (F:\Medusa\Portal\SkryptStore\backend\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (F:\Medusa\Portal\SkryptStore\backend\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (F:\Medusa\Portal\SkryptStore\backend\node_modules\express\lib\router\layer.js:95:5)
at F:\Medusa\Portal\SkryptStore\backend\node_modules\express\lib\router\index.js:284:15
at param (F:\Medusa\Portal\SkryptStore\backend\node_modules\express\lib\router\index.js:365:14)
at param (F:\Medusa\Portal\SkryptStore\backend\node_modules\express\lib\router\index.js:376:14)
at Function.process_params (F:\Medusa\Portal\SkryptStore\backend\node_modules\express\lib\router\index.js:421:3)
main.ts
import express = require('express');
const config = require('../medusa-config');
import { Medusa } from 'medusa-extender';
import { resolve } from 'path';
import { ProductModule, UserModule, StoreModule, OrderModule, InviteModule, RoleModule, PermissionModule } from 'medusa-marketplace';
async function bootstrap() {
const expressInstance = express();
await new Medusa(resolve(__dirname, '..'), expressInstance).load(
[
UserModule,
ProductModule,
StoreModule,
OrderModule,
InviteModule,
RoleModule,
PermissionModule
]
);
const port = config?.serverConfig?.port ?? 9000;
expressInstance.listen(port, () => {
console.info('Server successfully started on port ' + port);
});
}
bootstrap();
This.validateId_ is now an util and must be imported separatly
Hi @adrien2p, same issue here, I try to found this util on marketplace-plugin, medusa-extender and medusa core but couldn't find it to try to fix this issue. Do you know where this util is to fix this problem?
It is in medusa/dist/utils/validate-id if it is not already exported by the utils/index https://github.com/medusajs/medusa/blob/master/packages/medusa/src/utils/validate-id.ts
Also, most of the tile it is not used, which is why the core does not use it very much. If you only pass the id the util will not do anything
I'm trying to overwrite de created services by marketplace-plugin with extender to change this behavior to use the util for validateId and buildQuery, which was another failing method. Now all my class looks good but have trouble to override the service and gives me the next error:
medusa-server-default |
medusa-server-default | src/modules/user/user.service.ts(33,5): error TS2416: Property 'withTransaction' in type 'UserService' is not assignable to the same property in base type 'UserService'.
medusa-server-default | Type '(transactionManager: EntityManager) => UserService' is not assignable to type '(transactionManager?: EntityManager) => this'.
medusa-server-default | Type 'UserService' is not assignable to type 'this'.
medusa-server-default | 'UserService' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'UserService'.
My current class is this:
import { EntityManager } from "typeorm";
import EventBusService from "@medusajs/medusa/dist/services/event-bus";
import { FindConfig } from "@medusajs/medusa/dist/types/common";
import Utils from "@medusajs/medusa/dist/utils";
import { MedusaError } from "medusa-core-utils";
import MedusaMarketplaceUserService from "medusa-marketplace/dist/modules/user/user.service";
import { Service } from "medusa-extender";
import { User } from "medusa-marketplace/dist/modules/user/user.entity";
import UserRepository from "medusa-marketplace/dist/modules/user/user.repository";
type ConstructorParams = {
manager: EntityManager;
userRepository: typeof UserRepository;
eventBusService: EventBusService;
loggedInUser?: User;
};
@Service({ override: MedusaMarketplaceUserService })
export default class UserService extends MedusaMarketplaceUserService {
private readonly manager: EntityManager;
private readonly userRepository: typeof UserRepository;
private readonly eventBus: EventBusService;
constructor(private readonly container: ConstructorParams) {
super(container);
this.manager = container.manager;
this.userRepository = container.userRepository;
this.eventBus = container.eventBusService;
this.container = container;
}
withTransaction(transactionManager: EntityManager): UserService {
if (!transactionManager) {
return this;
}
const cloned = new UserService({
...this.container,
manager: transactionManager,
});
cloned.transactionManager_ = transactionManager;
return cloned;
}
public async retrieve(
userId: string,
config?: FindConfig<User>
): Promise<User> {
const userRepo = this.manager.getCustomRepository(this.userRepository);
const validatedId = Utils.validateId(userId);
const query = Utils.buildQuery({ id: validatedId }, config);
const user = await userRepo.findOne(query);
if (!user) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`User with id: ${userId} was not found`
);
}
return user as User;
}
public async addUserToStore(user_id, store_id) {
await this.atomicPhase_(async (m) => {
const userRepo = m.getCustomRepository(this.userRepository);
const query = Utils.buildQuery({ id: user_id });
const user = await userRepo.findOne(query);
if (user) {
user.store_id = store_id;
await userRepo.save(user);
}
});
}
}
I'm newbie with Typescript, but is this a good approach to fix the issue with extender?
getting the same error
Hi,
I'am trying to use this plugin but it doesn't works when i'am trying to create a new user because the following error appears:
And the request stay in "Loading..." state in Postman:
Any idea how what's happen ?
I can authenticate a user create with the
medusa
client (ex:medusa user -e test@test.com -p test
)But the
store_id
is null.My src/main.ts:
Thx for your help