Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async updateProgress(@Param('id') id: string, @Body() data: any, @CurrentUser() currentUser: IUser) {
const progress = await Progress.findById(id);
if (!progress) {
throw new NotFoundError();
}
const unit: IUnitModel = await Unit.findById(progress.unit);
ProgressController.checkDeadline(unit);
// set user
data.user = currentUser._id;
progress.set(data);
await progress.save();
return progress.toObject();
}
}
async deleteConfig(@Param('id') id: string) {
const config = await StudentConfig.findById(id);
if (!config) {
throw new NotFoundError();
}
await config.remove();
return {result: true};
}
}
async findOne(id): Promise {
const blog = await this.blogRepository.findOne(id);
if (!blog) {
throw new NotFoundError('blog is not found');
}
return blog;
}
async remove(@Param("id") id: number) {
let existingContact = await this.getRepo().findOneById(id);
if (!existingContact) {
throw new NotFoundError("Not found");
} else {
let result = await this.getRepo().remove(existingContact);
}
}
public async toggleRuleFile(name: string, checked: boolean) {
if (!this.exist(name)) {
throw new NotFoundError('找不到对应名称的转发规则集');
}
const ruleFile = this.rules[name];
ruleFile.checked = checked;
await this.saveRuleFile(name, ruleFile);
}
async getConfigurationWithSchema(@Param('id') id: number) {
const service = await this.servicesRepository.findOneOrFail({ id })
const config = this.context.config.getConfigurationWithSchema(service)
if (!config) {
throw new NotFoundError()
}
return config
}
async enrollStudent(@Param('id') id: string, @Body() data: any, @CurrentUser() currentUser: IUser) {
let course = await Course.findById(id);
if (!course) {
throw new NotFoundError();
}
if (course.enrollType === 'whitelist') {
const wUsers: IWhitelistUser[] = await WhitelistUser.find().where({courseId: course._id});
if (wUsers.filter(e =>
e.firstName === currentUser.profile.firstName.toLowerCase()
&& e.lastName === currentUser.profile.lastName.toLowerCase()
&& e.uid === currentUser.uid).length <= 0) {
throw new ForbiddenError(errorCodes.errorCodes.course.notOnWhitelist.code);
}
} else if (course.accessKey && course.accessKey !== data.accessKey) {
throw new ForbiddenError(errorCodes.errorCodes.course.accessKey.code);
}
if (course.students.indexOf(currentUser._id) < 0) {
course.students.push(currentUser);
await new NotificationSettings({
async update(article: Article): Promise<article> {
const old = await this.findOne(article.id);
if (!old) {
throw new NotFoundError('article is not found');
}
if (article.blog.id !== old.blog.id) {
throw new BadRequestError("blog id can't be changed");
}
article.tags = await this.relateTags(article.tags);
return this.articleRepository.save(Object.assign(old, article));
}
</article>
async createNewInstance(
@BodyParam('moduleName', { required: true }) serviceModuleName: string,
@BodyParam('instanceName', { required: true }) serviceInstanceName: string,
@BodyParam('config', { required: true, parse: true }) configuration: any,
) {
const serviceModule = (await this.context.serviceManager.getAvailableServices()).find(
el => el.moduleName === serviceModuleName,
)
if (!serviceModule) {
throw new NotFoundError()
}
const schema = nativeRequire(serviceModule.modulePath).Config
const fieldList = Reflect.getMetadata(
fieldListMetadataKey,
new schema(),
) as string[]
if (!fieldList.every(el => configuration[el] !== undefined)) {
throw new BadRequestError('Config does not match schema')
}
if (!serviceModule) {
throw new NotFoundError('Service with given name does not exist')
}
const service = new Service()
public uninstall(pluginName: string) {
if (!this.has(pluginName)) {
throw new NotFoundError('该插件不存在');
}
return new Promise((resolve, reject) => {
const uninstall = () => {
npm.commands.uninstall([pluginName, this.pluginInstallDir], err => {
if (err) {
return reject(err);
}
const restPlugins = this.getPlugins().filter(p => p.name !== pluginName);
this.setPlugins(restPlugins);
return resolve(restPlugins);
});
};
const npmConfig = { loglevel: 'silent', prefix: this.pluginInstallDir };
this.loadNpmConfig(npmConfig, uninstall);
});
}