Dashboard Temp Share Shortlinks Frames API

HTMLify

remove_user.js
Views: 6 | Author: cody
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';

const Aspect = require('./operation').Aspect;
const CommandOperation = require('./command');
const defineAspects = require('./operation').defineAspects;
const handleCallback = require('../utils').handleCallback;
const WriteConcern = require('../write_concern');

class RemoveUserOperation extends CommandOperation {
  constructor(db, username, options) {
    const commandOptions = {};

    const writeConcern = WriteConcern.fromOptions(options);
    if (writeConcern != null) {
      commandOptions.writeConcern = writeConcern;
    }

    if (options.dbName) {
      commandOptions.dbName = options.dbName;
    }

    // Add maxTimeMS to options if set
    if (typeof options.maxTimeMS === 'number') {
      commandOptions.maxTimeMS = options.maxTimeMS;
    }

    super(db, commandOptions);

    this.username = username;
  }

  _buildCommand() {
    const username = this.username;

    // Build the command to execute
    const command = { dropUser: username };

    return command;
  }

  execute(callback) {
    // Attempt to execute command
    super.execute((err, result) => {
      if (err) return handleCallback(callback, err, null);
      handleCallback(callback, err, result.ok ? true : false);
    });
  }
}

defineAspects(RemoveUserOperation, Aspect.WRITE_OPERATION);

module.exports = RemoveUserOperation;