Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else {
// Update user's data
user.firstName = data.firstName;
user.lastName = data.lastName;
await user.save();
}
try {
await authPlugin.createUser({ data: args.data, user, permanent: true }, context);
result.authUser = true;
} catch {
// Update firstName/lastName, but do not touch the existing password
await authPlugin.updateUser({ data: omit(args.data, ["password"]), user }, context);
}
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(result);
};
user.lastName = data.lastName;
await user.save();
}
try {
await authPlugin.createUser({ data: args.data, user, permanent: true }, context);
result.authUser = true;
} catch {
// Update firstName/lastName, but do not touch the existing password
await authPlugin.updateUser({ data: omit(args.data, ["password"]), user }, context);
}
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(result);
};
const authPlugin = context.plugins
.byType("security-authentication-provider")
.filter(pl => pl.hasOwnProperty("createUser"))
.pop();
try {
await authPlugin.createUser({ data: args.data, user }, context);
} catch {
// If user already exists we don't do anything on the auth provider side.
}
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(user);
};
try {
await user.populate(args.data).save();
const authPlugin = context.plugins
.byType("security-authentication-provider")
.filter(pl => pl.hasOwnProperty("createUser"))
.pop();
try {
await authPlugin.createUser({ data: args.data, user }, context);
} catch {
// If user already exists we don't do anything on the auth provider side.
}
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(user);
};
each(invalidFields, ({ code, data, message }, name) => {
if (code !== WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
return;
}
const path = prefix ? `${prefix}.${name}` : name;
if (Array.isArray(data)) {
return each(data, (err, index) => {
const {
data: { invalidFields },
message
} = err;
if (!invalidFields) {
formatted[`${path}.${index}`] = message;
return;
}
export default async (root: any, args: Object, context: Object) => {
const { File } = context.models;
const model = await File.findOne({ query: { src: args.src } });
if (!model) {
return new NotFoundResponse();
}
try {
await model.populate(args.data).save();
} catch (e) {
if (
e instanceof WithFieldsError &&
e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS
) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || "VALIDATION_FAILED_INVALID_FIELDS",
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data || null
});
}
return new Response(model);
};
export const resolveCreate = (getModel: GetModelType) => async (
root: any,
args: Object,
context: Object
) => {
const Model = getModel(context);
const model = new Model();
try {
await model.populate(args.data).save();
} catch (e) {
if (
e instanceof WithFieldsError &&
e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS
) {
const fieldError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: fieldError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: fieldError.message,
data: fieldError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(model);
};
const model = await Model.findById(args.id);
if (!model) {
return notFound(args.id);
}
try {
await model.populate(args.data);
await model.save();
} catch (e) {
if (
e instanceof WithFieldsError &&
e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS
) {
const fieldError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: fieldError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: fieldError.message,
data: fieldError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data || null
});
}
return new Response(model);
};
}
try {
await user.populate(data).save();
const authPlugin = context.plugins
.byType("security-authentication-provider")
.filter(pl => pl.hasOwnProperty("updateUser"))
.pop();
await authPlugin.updateUser({ data: args.data, user }, context);
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(user);
};
if (!user) {
return new NotFoundResponse(id ? `User "${id}" not found!` : "User not found!");
}
try {
await user.populate(data).save();
const authPlugin = context.plugins
.byType("security-authentication-provider")
.filter(pl => pl.hasOwnProperty("updateUser"))
.pop();
await authPlugin.updateUser({ data: args.data, user }, context);
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(user);
};