Skip to content

Instantly share code, notes, and snippets.

@tolgig
Created February 7, 2021 10:50
Show Gist options
  • Select an option

  • Save tolgig/3f3cfbdadc546afbb917cceaabf5d9cd to your computer and use it in GitHub Desktop.

Select an option

Save tolgig/3f3cfbdadc546afbb917cceaabf5d9cd to your computer and use it in GitHub Desktop.
public async updateProfile(profileDto: EditProfilDto): Promise<IUser> {
const userFromDb = await this.userModel.findOne({
email: profileDto.email,
});
// Dont found any user with this email
if (!userFromDb)
throw new HttpException('COMMON.USER_NOT_FOUND', HttpStatus.NOT_FOUND);
if (profileDto.username)
userFromDb.username = profileDto.username.toLowerCase().trim();
if (profileDto.username)
userFromDb.displayName = profileDto.username.trim();
if (profileDto.birthDate) userFromDb.birthDate = profileDto.birthDate;
if (profileDto.sexroles)
userFromDb.sexroles = profileDto.sexroles.map(role => {
return { _id: mongoose.Types.ObjectId(role._id) };
});
if (profileDto.searchIdentFilter)
userFromDb.searchIdentFilter = profileDto.searchIdentFilter.map(
searchFilter => {
return { _id: mongoose.Types.ObjectId(searchFilter._id) };
},
);
if (profileDto.ident)
userFromDb.ident = { _id: mongoose.Types.ObjectId(profileDto.ident._id) };
if (profileDto.orient)
userFromDb.orient = {
_id: mongoose.Types.ObjectId(profileDto.orient._id),
};
if (profileDto.imagesSetupIsFinished)
userFromDb.imagesSetupIsFinished = profileDto.imagesSetupIsFinished;
if (profileDto.description) userFromDb.description = profileDto.description;
if (profileDto.descriptionSetupIsFinished)
userFromDb.descriptionSetupIsFinished =
profileDto.descriptionSetupIsFinished;
if (profileDto.pictures) userFromDb.pictures = profileDto.pictures;
if (profileDto.wantedAge) userFromDb.wantedAge = profileDto.wantedAge;
// Noting that your data must be in longitude then latitude order
// as supported by GeoJSON and all MongoDB geospatial query forms.
// location: { type: { type: String }, coordinates: [], lastSeen: 'String' },
if (profileDto.newLocation) {
userFromDb.location = {
type: 'Point',
coordinates: [
profileDto.newLocation.coords.longitude,
profileDto.newLocation.coords.latitude,
],
lastSeen: Date.now(),
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment