Skip to content

Instantly share code, notes, and snippets.

@sodiray
Last active August 9, 2022 23:02
Show Gist options
  • Select an option

  • Save sodiray/e5df8578ff71f8c054d94d48e6b527d0 to your computer and use it in GitHub Desktop.

Select an option

Save sodiray/e5df8578ff71f8c054d94d48e6b527d0 to your computer and use it in GitHub Desktop.
import { omit } from 'radash'
import * as t from 'src/types'
import { ObjectId } from 'mongodb'
export class Listing {
static toModel(document: t.ListingDocument): t.Listing {
return omit(document, ['_id', '_userId', '_categoryId'])
}
static toDocument(model: t.Listing): t.ListingDocument {
return {
...model,
_id: new ObjectId(model.id),
_userId: new ObjectId(model.userId),
_categoryId: new ObjectId(model.categoryId)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment