Skip to content

Commit

Permalink
fix: delete ops should update updated ts (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Dec 10, 2021
1 parent d6ee483 commit 88b6c09
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ export class DBClient {
* @param {string} cid
*/
async deleteUpload (userId, cid) {
const now = new Date().toISOString()
/** @type {{ data: import('./db-client-types').UploadItem, error: PostgrestError }} */
const { data, error } = await this._client
.from('upload')
.update({
deleted_at: new Date().toISOString()
deleted_at: now,
updated_at: now
})
.match({
source_cid: cid,
Expand Down Expand Up @@ -684,11 +686,13 @@ export class DBClient {
* @param {number} keyId
*/
async deleteKey (userId, keyId) {
const now = new Date().toISOString()
/** @type {{ data, error: PostgrestError }} */
const { data, error } = await this._client
.from('auth_key')
.update({
deleted_at: new Date().toISOString()
deleted_at: now,
updated_at: now
})
.match({
id: keyId,
Expand Down
7 changes: 7 additions & 0 deletions packages/db/test/upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ describe('upload', () => {
// Delete previously created upload
await client.deleteUpload(user._id, otherCid)

const { data: deletedUpload } = await client._client
.from('upload')
.select('*')
.eq('id', uploadId)
.single()
assert.strictEqual(deletedUpload.updated_at, deletedUpload.deleted_at)

// Should fail to delete again
let error
try {
Expand Down
7 changes: 7 additions & 0 deletions packages/db/test/user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ describe('user operations', () => {
const { _id } = await client.deleteKey(user._id, authKey._id)
assert(_id, 'key deleted')

const { data: deletedKey } = await client._client
.from('auth_key')
.select('*')
.eq('id', _id)
.single()
assert.strictEqual(deletedKey.updated_at, deletedKey.deleted_at)

const finalKeys = await client.listKeys(user._id)
assert(finalKeys, 'final keys fetched')
assert.deepEqual(finalKeys.length, keys.length - 1, 'user had auth key deleted')
Expand Down

0 comments on commit 88b6c09

Please sign in to comment.